To fix Redis connection refused error 111 in WordPress: Add define('WP_REDIS_DISABLE', true); to wp-config.php to regain dashboard access, start the daemon using sudo systemctl start redis-server, verify the service listens on 127.0.0.1:6379 via ss -tlpn | grep redis, and ensure WP_REDIS_HOST matches your server binding or points to a valid Unix socket path.[1][2]
Follow this system administrator runbook to restore broken object caching, diagnose socket permissions, and re-establish secure in-memory database acceleration across Apache, Nginx, and LiteSpeed environments.[1][3]
Understanding Redis Connection Refused (Error 111) in WordPress
In Linux operating environments, ECONNREFUSED (standard POSIX error code 111) occurs at the kernel socket layer when a client attempts to establish a TCP or Unix socket handshake against an address or port where no listening process is actively bound.[2]
In WordPress, persistent object caching plugins (such as Redis Object Cache or LiteSpeed Cache) intercept database queries via a drop-in file located at wp-content/object-cache.php.[1] When PHP executes an application request, it instantiates the PhpRedis extension or Predis library to query the in-memory cache.[3] If the Redis daemon crashes, exhausts memory allocations, listens on an incorrect IP address, or blocks access via missing file system socket permissions, PHP halts execution and generates a fatal error or a White Screen of Death (WSoD):[1]
RedisException: Connection refused in /var/www/html/wp-content/object-cache.php:742
Stack trace:
#0 [internal function]: Redis->connect('127.0.0.1', 6379, 1.5, NULL, 100, 1.5)
#1 /var/www/html/wp-content/object-cache.php(742): Redis->connect()
For high-traffic WooCommerce applications running on Pakistan dedicated servers or high-memory international cloud infrastructure, persistent object caching is critical for maintaining sub-100ms response times. Resolving Error 111 requires verifying daemon state, network binding, and configuration parameters.[4]
Emergency Recovery: Regaining Access to wp-admin
When Error 111 triggers a site-wide crash, administrators are frequently locked out of both the front end and the WordPress administrative portal.[1] Perform immediate emergency bypass before inspecting system logs.
Method 1: Define the Emergency Bypass Constant
Edit wp-config.php and append the bypass directive immediately above the /* That's all, stop editing! */ line:
define( 'WP_REDIS_DISABLE', true );
This constant instructs the drop-in script to bypass the Redis backend and fallback to transient direct MySQL queries without breaking active user sessions.[1]
Method 2: Rename the Drop-in File via CLI
If the site fails to load despite configuration constants, remove the drop-in file:
cd /var/www/html/wp-content
mv object-cache.php object-cache.php.disabled
WordPress immediately resumes standard query operations, allowing you to access the dashboard and investigate underlying infrastructure faults.[1]
Diagnostic Matrix: Redis Connection Failure Scenarios
| Failure Scenario | Root Cause | Diagnostic Command | Permanent Solution |
|---|---|---|---|
| Daemon Inactive | Redis crashed due to Out-of-Memory (OOM) or unhandled signal | systemctl status redis-server |
Restart service; tune maxmemory and maxmemory-policy in redis.conf.[2] |
| IP Binding Mismatch | Redis listens exclusively on IPv6 (::1) while PHP connects to IPv4 (127.0.0.1) |
ss -tlpn | grep 6379 |
Update bind 127.0.0.1 ::1 in /etc/redis/redis.conf.[2] |
| Socket Permission Denied | Web server user (www-data / nginx) lacks read/write access to redis.sock |
ls -la /var/run/redis/redis.sock |
Add web user to redis group; set unixsocketperm 770.[3] |
| Port Mismatch | Custom port assigned in Redis configuration; default 6379 assumed in wp-config.php |
redis-cli info | grep tcp_port |
Set define('WP_REDIS_PORT', <custom_port>); in wp-config.php.[1] |
| Docker Isolation | WordPress container cannot resolve 127.0.0.1 inside its own network namespace |
docker exec -it <wp_container> ping redis |
Set define('WP_REDIS_HOST', 'redis'); and attach containers to shared bridge network.[4] |
Step-by-Step Terminal Checklist: Fix Redis Connection Refused Error 111 in WordPress
Step 1: Verify Redis Daemon State and Memory Allocation
Connect via SSH to your host server and verify if the service daemon is active:
# Ubuntu / Debian
sudo systemctl status redis-server
# AlmaLinux / Rocky Linux / CentOS
sudo systemctl status redis
If the service is stopped or failed, examine the system journal to verify if the Linux Out-of-Memory (OOM) killer terminated the process:
sudo journalctl -u redis-server --since "1 hour ago" --no-pager
dmesg -T | grep -i oom
Start and enable the service on boot:
sudo systemctl enable --now redis-server
redis-cli ping
Expected Output: PONG[2]
Step 2: Validate Network Binding in redis.conf
Open the primary configuration file:
- Ubuntu/Debian:
/etc/redis/redis.conf - RHEL/AlmaLinux:
/etc/redis/redis.confor/etc/redis.conf
Inspect the bind directive:
bind 127.0.0.1 ::1
protected-mode yes
port 6379
Verify that the process is actively listening on the loopback interface:
ss -tlpn | grep 6379
Expected Output:
LISTEN 0 511 127.0.0.1:6379 0.0.0.0:* users:(("redis-server",pid=1420,fd=6))
LISTEN 0 511 [::1]:6379 [::]:* users:(("redis-server",pid=1420,fd=7))
If the output only displays [::1]:6379 (IPv6), PHP connections to 127.0.0.1 fail with Error 111.[2] Ensure 127.0.0.1 is explicitly declared.
Step 3: Match Configuration Constants in wp-config.php
Inspect your WordPress configuration file (wp-config.php) to confirm the connection parameters match your server topology.[1]
Standard TCP Loopback:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_TIMEOUT', 1.5 );
define( 'WP_REDIS_READ_TIMEOUT', 1.5 );
define( 'WP_REDIS_DATABASE', 0 );
If your Redis server requires authentication, include the password constant:
define( 'WP_REDIS_PASSWORD', 'your_secure_redis_password_here' );
Step 4: Configure High-Performance Unix Sockets
Connecting via Unix domain sockets eliminates TCP network stack overhead and provides up to a 20% latency reduction.[3] However, misconfigured socket permissions are the leading cause of Error 111 when using sockets.[3]
- Open
/etc/redis/redis.confand configure the socket path and permissions:
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
- Add your web server user (
www-dataon Ubuntu ornginx/apacheon RHEL) to theredisgroup:
sudo usermod -aG redis www-data
- Restart Redis and PHP-FPM:
sudo systemctl restart redis-server
sudo systemctl restart php8.2-fpm
- Update
wp-config.phpto target the socket:
define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );
Step 5: Resolve Containerized and Docker Network Isolation
If your WordPress stack runs inside Docker, specifying 127.0.0.1 in wp-config.php targets the loopback interface of the WordPress container itself, resulting in Error 111.[4]
- Confirm the Redis service name defined in
docker-compose.yml:
services:
wordpress:
image: wordpress:php8.2-fpm
networks:
- app-tier
redis:
image: redis:7-alpine
command: redis-server --appendonly yes
networks:
- app-tier
networks:
app-tier:
driver: bridge
- Configure
wp-config.phpto target the Docker service DNS alias:
define( 'WP_REDIS_HOST', 'redis' );
define( 'WP_REDIS_PORT', 6379 );
Pro Tips and Common Pitfalls
Pro Tip: Prevent OOM crashes by assigning a strict memory ceiling and eviction policy in redis.conf. For a 16 GB server, allocate 2 GB to Redis: maxmemory 2gb combined with maxmemory-policy allkeys-lru. This ensures Redis purges stale object cache keys rather than triggering Linux kernel termination.[2]
Critical Pitfall: Never leave protected-mode no enabled on a server exposed to public interfaces without authentication. If Redis binds to 0.0.0.0 without a password, automated network crawlers will exploit unauthenticated remote access to inject malicious crontabs or compromise host files.[2]
Frequently Asked Questions (PAA)
What causes Redis connection refused Error 111 in WordPress?
Error 111 indicates that the Redis service is either stopped, crashed due to memory exhaustion, listening on a different port/IP than configured in wp-config.php, or blocked by missing Unix socket permissions (/var/run/redis/redis.sock).[1][2]
Should I use PhpRedis or Predis in WordPress?
PhpRedis is a compiled C extension for PHP that executes significantly faster and consumes less memory than Predis (a pure PHP library).[3] Install the native module via sudo apt install php-redis or sudo pecl install redis for high-throughput production environments.[3]
How do I verify that Redis Object Cache is actively storing keys?
Connect via terminal and run the monitor or keyspace inspection commands:[2]
redis-cli info keyspace
redis-cli monitor
Refresh a page on your WordPress website. The monitor feed should stream active GET and SET operations matching your table_prefix.
Does clearing Redis cache delete WooCommerce customer orders?
No. Persistent object caching holds temporary query results, transients, and pre-computed options in memory. All permanent transactional data, user accounts, and WooCommerce orders reside securely in the underlying MySQL database.[1]
Accelerate Your Web Applications with Nextgen Hosting
Eliminate database bottlenecks and server crashes with high-performance bare metal and Cloud VPS from Nextgen Hosting. Experience dedicated NVMe storage, pre-configured Redis caching, and Tier-III datacenter connectivity.
Pakistan Bare Metal Servers • International Dedicated Infrastructure • High-Speed Cloud VPS
Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute formal server management advice. Nextgen Hosting accepts no liability for configuration errors or data loss resulting from reliance on this content.
Sources & Official References
- WordPress.org Plugin Directory - Redis Object Cache Technical Documentation: https://wordpress.org/plugins/redis-cache/
- Redis Official Documentation - Configuration and Network Security: https://redis.io/docs/management/config/
- PhpRedis Extension Repository & Unix Domain Socket Guidance: https://github.com/phpredis/phpredis
- Docker Networking Concepts and Container Inter-Process Communication: https://docs.docker.com/network/
