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

Tenatious's avatar

Load Balancer - Redis Session Persistence

Hi,

I'm having an issue with session data not persisting when using a load balancer and Redis, all configured via Forge.

The setup is as follows:

  • 2 x application servers
  • 1 x load balancer
  • 1 x redis cache and session server
  • 1 x mysql server.

At the moment I have the load balancer set up as "Round robin". However, on every page refresh that it swaps to the other server, the session ID is changing and so it's screwing my application. I need the session to persist over the server swaps.

I'm using a remote Redis application and as far as I'm aware I have all the .env variables set correctly on both application servers.

If I run Redis-cli keys* on the Redis server, I can see lots of _cache files being generated on each page refresh.

I have tried adding the load balancer IP to the proxy section of TrustedProxies but this did nothing.

This is the environment settings I have, duplicated on both application servers:

CACHE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_CONNECTION=session
SESSION_DOMAIN=".domain.com"

REDIS_CLIENT=predis
REDIS_HOST=111.111.111.111
REDIS_PASSWORD=""
REDIS_PORT=6379

Anything else I can look at?

0 likes
1 reply
circleback's avatar

Are you setting the same key in APP_KEY for each app server?

Without it, you will lose login session data under the round robin load balancer environment.

Please or to participate in this conversation.