I am trying to deploy a Laravel 5.2 app on AWS Elastic Beanstalk. Everything works fine, Except SESSIONS. Prior to deploying it on the Beanstalk, I had been working on the app on EC2, and I had no problems with sessions. For SESSION_DRIVER env option, I have tried database, cookie and file. They all worked on EC2 but none of them worked on Elastic Beanstalk.
After Googling and SOing a lot, I found out about Sticky Sessions. This is a setting you need to enable on the load balancer of your elastic beanstalk. This is available in the configuration dashboard of the elastic beanstalk.
So, I enabled Sticky Sessions, by choosing both, Use Load Balancer Generated Session AND Use App Generated Session option from the dropdown. Still the sessions don’t work.
I have been looking around for other solutions but all routes point to Sticky Sessions.
Has anyone else faced this issue? If so, how did you solve it? Any help would be highly appreciated.
Advertisement
Answer
On speaking with AWS Support, they suggested the following working solution.
- In your web app root, create a folder called .ebextensions
Open any text editor and paste the following policy
Resources: AWSEBLoadBalancer: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: Listeners: - InstancePort: 80 InstanceProtocol: HTTP LoadBalancerPort: 80 PolicyNames: - CookiePolicy Protocol: HTTP AppCookieStickinessPolicy: - CookieName: laravel_session PolicyName: CookiePolicy
Save this file in the .ebextensions folder that you created in step 1.
- Redeploy the app to your beanstalk. Sessions should now be working