Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

squibby's avatar

Database session driver recording user_id as null on aws with load balancer. Help

In homestead when using database session driver I don't have problems when logging into application. Everything works as expected. I have since deployed my app to 2 aws ec2 and setup a load balancer pointing to these instances all through forge. I have an rds instance setup for the database.

I can access the apps fine through each of their ips. But if I go to the load balancer at www.mydomain.com I can reach the login page but after login i get exception thrown. Checking the logs shows 'production.ERROR: Illuminate\Session\TokenMismatchException'.

After checking the sessions table in the database it is recording null instead of the logged in user_id like it should.

Does anyone know why this is happening when I am using a load balancer? I would really appreciate some help.

Thank you.

0 likes
1 reply
squibby's avatar
squibby
OP
Best Answer
Level 8

Fixed by using sticky session on aws load balancer, and changing session driver from file/database to cookie.

Please or to participate in this conversation.