Redis connection refused in Laravel

When Laravel uses Redis for cache, sessions or queues, a "Connection refused" error means it cannot reach the Redis server. Usually the service is down or the host is wrong, especially in Docker.

Mark van Eijk 1 minute read Laravel
  1. About the error
  2. Why do I see this error
  3. Solution
  4. Check Redis is running
  5. Verify the connection settings
  6. Docker: use the service name
  7. Clear cached config

About the error

Predis\Connection\ConnectionException: Connection refused [tcp://127.0.0.1:6379]

(Or the phpredis equivalent.) Laravel tried to open a connection to Redis and nothing accepted it at that address. This is different from an authentication or wrong-database error, the connection never got established at all.

Why do I see this error

  • Redis isn't running.
  • REDIS_HOST or REDIS_PORT is wrong.
  • In Docker, 127.0.0.1 from inside the app container points at the container itself, not the Redis container.
  • Redis requires a password (requirepass) that you haven't set in .env.

Solution

Check Redis is running

systemctl status redis-server
redis-cli ping     # should reply PONG

If ping replies PONG, the server is up and the problem is how Laravel addresses it.

Verify the connection settings

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=null

CACHE_STORE=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

Docker: use the service name

Inside a container, 127.0.0.1 is the container, not the host. Set REDIS_HOST to the service name from your docker-compose.yml:

REDIS_HOST=redis
services:
  redis:
    image: redis:7
    ports:
      - "6379:6379"

Clear cached config

If you changed .env but Laravel still connects to the old address, the config is cached:

php artisan config:clear

See environment variables in Laravel for how these values are loaded, and SQLSTATE[HY000] [2002] Connection refused for the same class of "can't reach the service" problem with MySQL.