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

nextit's avatar

Running laravel on multiple EC2 Servers

Hi. I am using 2 AWS EC2 to run laravel applications. After I setup the Amazon SSL and loadbalancer for 2 EC2, the login doesnt work. it repeats redirecting. I am using cookie for session not file sessions.

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

Everytime i redirect, XSRF-TOKEN and laravel_session cookies are changing.

I sometimes get TokenMismatchException error.

Do i have to set up seomthing for sessions? can we store session files to S3?

Thanks.

0 likes
1 reply
Cronix's avatar

You'd want to use a shared database that both servers are accessing, or shared redis/memcached for session storage. Then it won't matter which server they are actually on. Since csrf tokens are stored in session, it should clear that up too using a common session store.

Please or to participate in this conversation.