AWS Elastic Beanstalk and PHP sessions

谁都会走 提交于 2019-11-30 09:20:41
hek2mgl

Moving your application to Elastic Beanstalk means that from now on your application will possibly run on 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 does not possess that session file on disk (you seem to be using the file-based session handler as shown in the question).

Solution A (preferred)
You need to store sessions in a shared location where they can be accessed by all of your web server instances. Amazon typically recommends DynamoDB for this, but it could also be MySQL or Redis or even the Elastic Cache provided by AWS.

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 L.B. will unwrap HTTP(S) packets, look for the session cookie and then forward the request to the correct web server where the session lives.

Ryan Badger

You can also add this to your elastic beanstalk project.config file:

"/etc/httpd/conf.d/php.conf" :
   content: |
     php_value session.save_path "/tmp"

that will just set the session save path for you

Actually I've found a very easy solution with 2 lines of PHP-code only that worked for me:

http://technosophos.com/2013/10/09/getting-php-sessions-work-aws-elastic-beanstalk.html

Add that your php and you are done.

<?php
$dir = sys_get_temp_dir();
session_save_path($dir);
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!