trojansc's avatar

'laravel_session' cookie is not set

As the title, the 'laravel_session' cookie is not set on the production server, and the form is failed to process.

I'm running Laravel version 5.6, PHP 7.2.4-1 and ubuntu16.04.1 on the production server.

However, I run the same code and setting locally in MAMP. it's working fine. The 'laravel_session' cookie is created automatically, and I can view it inside the browser.

0 likes
25 replies
Cronix's avatar

Are sessions being generated in /app/Storage/Framework/Sessions (assuming you're using the file driver)? Perhaps it's not able to create them (folder permissions?) so it can't generate the cookie? Is the cookie domain set properly in /config/Session.php?

trojansc's avatar

@Cronix I am using database for the Session.

'driver' => env('SESSION_DRIVER', 'database'),

Cronix's avatar

Are sessions being generated in the db then? Did you check the cookie domain? Does it actually match your host name? Any errors in the logs, or in your browser console? Are any cookies being generated at all (check browser tools)? Are you using php end tags in any of your files (you shouldn't)? Are there any spaces or blank lines before the php open tag in your files? That could create output which could break cookie generation. Have you tried switching to the session file driver to see if that works?

trojansc's avatar

@Cronix

Are sessions being generated in the db then? YES

Did you check the cookie domain? YES and set it as ".mywebsite.com"

Are any cookies being generated at all (check browser tools)? NO Cookies being generated. This is the problem.

Are you using php end tags in any of your files (you shouldn't)? NO

Are there any spaces or blank lines before the php open tag in your files? NO

Have you tried switching to the session file driver to see if that works? Tried before, but also not working.

Cronix's avatar

Are you behind a load balancer or another service like cloudfare? Is there anything between your server and the public internet?

Cronix's avatar

That doesn't answer the question though. You can use load balancers and cloudfare and a number of other services in front of the aws server.

trojansc's avatar

@Cronix

I only create an EC2 instance in AWS. I didn't use any load balancers or other services in front of the aws server.

Cronix's avatar

I'm sorry, I really don't have any other ideas. :/

roerjo's avatar

I know this is an old conversation, but I just wanted to bring up @cronix mentioning being behind a load balancer or some other service in front of the server. This same issue just happened to me and we are using AWS Cloudfront in front our our ECS setup. We needed to setup Cloudfront to allow cookies to be forwarded. After we fixed that, we were good to go. Thanks for bringing that up @cronix !

Anishdhanka's avatar

I have also faced the same issue. it took me several days to debug the problem . so its output buffer limit issue in php.ini. technically PHP sends output as bytes which missing Set-cookie header in the request due to limit. I updated output_buffering = 16384 in php.ini which worked for me.

18 likes
ravatsinh's avatar

@Anishdhanka your solution worked for me after wasting 4-5 hours i just found cookie is not generated and came across your solution and its worked thank you

1 like
Hampni's avatar

@Anishdhanka Thank you so much, you saved my last nerves. Your comment really helped in my issue. All the best my friend i even registered just to say you my thanks. All the best

mitulgolakiya's avatar

@Anishdhanka you saved me. After wasting a lot of time, finally, it worked. Though I need to set a value bit higher. But it worked.

bastihilger's avatar

@Anishdhanka And me too! This was a problem in one application when I switched to Laravel Herd, and now it is fixed, thank you!

mohab19's avatar

I spent 2 days trying to fix the issue, thank you very much man .. really

Please or to participate in this conversation.