0
votes

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.

1
One point you could clarify is whether you were using Elastic Load Balancer before on top of your EC2 instance(s).Taylor Edmiston
@tedmiston No I wasn't using a Load Balancer before. I believe the problem exists with the load balancer not holding session state with the EC2 instancenikisfree
I believe so too. I haven't worked with Laravel, but I've experienced a similar problem with Django sessions and ELB. Have you tried only using app generated sessions? IIRC sticky sessions solved our issue, but it's been a while. Perhaps using aws elb describe-load-balancers from a shell would help debug an issue at that level. docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/…Taylor Edmiston

1 Answers

1
votes

On speaking with AWS Support, they suggested the following working solution.

  1. In your web app root, create a folder called .ebextensions
  2. 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
    
  3. Save this file in the .ebextensions folder that you created in step 1.

  4. Redeploy the app to your beanstalk. Sessions should now be working