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

lakinduk's avatar

laravel login with load balancer gives 419 page expired error

I have created 2 Laravel projects (both are same) and running in separate digital ocean droplets under a Digital Ocean load balancer.

When I access the web page with load balancer IP, it works fine but in the login page it gives me a 419 page expired error. When I try the servers separately, it works without an issue.

I've gone through some articles and found out the session created at the login redirects to the next server because of the load balancer.

Is there anyone who can help me to fix this issue?

0 likes
6 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

Make sure to use database session driver.

2 likes
lakinduk's avatar

thank you for the reply. Im very beginner to this. Any guide on how to do that ?

lakinduk's avatar

Thanks alot! It worked !

I just looked up the Laravel documentation for database session driver as @jlrdw and @lucasantonio mentioned. Change the session_drive=file to session_drive=database in .env file.

then run these commands:

	php artisan session:table

	php artisan migrate

Now the sessions are stored in database instead of individual servers. It fixed the conflict!

For reference, see Laravel documentation session

1 like
jlrdw's avatar

Glad you got it fixed.

1 like
ndtvinh14's avatar

@jlrdw Hi, I know it's late to join this conversation, but after changing session_drive=file to database, do I need to change the 'database' value in anywhere else such as config file, etc. ?

1 like

Please or to participate in this conversation.