AWS弹性魔豆和PHP会议 [英] AWS Elastic Beanstalk and PHP sessions

查看:115
本文介绍了AWS弹性魔豆和PHP会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司目前已开发PHP应用程序在一个AWS EC2实例,但我已经决定将它移动到弹性魔豆采取的自动缩放功能优势。

I currently have a php application in development on an AWS EC2 instance but I've decided to move it to Elastic Beanstalk to take advantage of the autoscaling functionality.

虽然大部分的应用程序迁移到新的弹性魔豆EC2实例完美,我快到关于PHP会议的问题。看来,PHP会话保存路径是不可写,根据由PHP生成以下消息:

While most of the application migrated to the new Elastic Beanstalk EC2 instances flawlessly, I'm running into an issue regarding php sessions. It seems that the php session save path is unwritable, according to the following message generated by php:

 Warning: Unknown: open(/var/lib/php/5.5/session/sess_uc1dpvmoq5fikcv0q2kogker15, O_RDWR)
 failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write
 session data (files). Please verify that the current setting of session.save_path is
 correct (/var/lib/php/5.5/session) in Unknown on line 0

有没有解决这个办法,而无需修改php.ini或任何CHMODing?我想对默认的弹性魔豆EC2实例我的应用程序运行,而无需使用自定义的AMI。我希望,这样一个简单的使用PHP的会话应该是默认不允许的!

Is there any way around this without modifying PHP.ini or CHMODing? I would like to have my application run on the default Elastic Beanstalk EC2 instances without using custom AMIs. I would hope that such a simple use of php sessions should be allowed by default!

推荐答案

移动你的应用程序弹性魔豆意味着,从现在开始您的应用程序上可能有多个物理Web服务器实例上运行。 (这是你付出的东西)。这意味着,一个有效的会话ID的请求可能(您正在使用会话文件处理程序如图中的问题)转发到有没有在磁盘上的会话文件服务器。

Moving your application to Elastic Beanstalk means that from now on your application runs on possibly multiple physical web server instances. (That's what you're paying for). This means that a request with a valid session id could be forwarded to a server which hasn't the session file on disk (you are using session file handler as shown in the question)..

解决方案A (preferred):你需要存储会话在那里他们可以由所有的Web服务器实例的访问的地方。这可能是像MySQL或Redis的,甚至是弹性缓存由AWS提供的数据库。

Solution A (preferred): You need to store sessions in a place where they could being accessed by all of your web server instances. This could be a database like mysql or redis or even the Elastic Cache provided by AWS.

溶液B (慢,不可靠的,需要SSL端接负载平衡器):配置负载平衡器,它使用粘会话的方式。这意味着磅将解开HTTP(S)数据包,查找会话cookie,然后将请求转发到Web服务器的会话生命。

Solution B (slower,unreliable, needs SSL termination at load balancer): Configure your load balancer in a way that it uses "sticky" sessions. This means that the lb will unwrap http(s) packets, looks for the session cookie and then forwards the request to the web server where the session lives.

这篇关于AWS弹性魔豆和PHP会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆