How to Fix Redis Connection Refused Error in WordPress

Redis is a powerful in-memory caching system that significantly improves the performance of WordPress websites. Many hosting platforms use Redis to reduce database queries and speed up page loading.

However, sometimes WordPress users encounter an error like this:

RedisException: Connection refused

or

Error establishing Redis connection

When this happens, WordPress caching stops working and your website may become slower or display errors.

The good news is that Redis connection refused errors are usually easy to fix once you identify the cause.

In this guide, we will cover:

  • What causes Redis connection errors
  • How to troubleshoot Redis issues
  • Step-by-step fixes
  • Best practices to prevent Redis problems

What Causes Redis Connection Refused in WordPress?

Before fixing the problem, it’s important to understand why the error occurs.

The most common reasons include:

1. Redis Server Not Running

The Redis service may have stopped or crashed.

When WordPress tries to connect, the server refuses the connection.


2. Incorrect Redis Host or Port

WordPress connects to Redis using a host and port defined in the configuration.

Default Redis port:

6379

If this port changes or is blocked, the connection fails.


3. Firewall Blocking Redis

Sometimes server firewall rules block Redis connections.


4. Wrong Redis Configuration in WordPress

Redis settings are usually stored in:

wp-config.php

Incorrect values will break the connection.


5. Redis Plugin Issues

WordPress caching plugins like:

  • Redis Object Cache
  • LiteSpeed Cache
  • W3 Total Cache

may generate connection errors if misconfigured.


Step 1: Check if Redis Server is Running

The first step is to confirm that Redis is active.

Run the following command on your server:

sudo systemctl status redis

If Redis is running, you will see:

active (running)

If Redis is stopped, start it with:

sudo systemctl start redis

Then enable automatic startup:

sudo systemctl enable redis

Step 2: Test Redis Connection

You can test Redis using the CLI tool.

Run:

redis-cli ping

If Redis works properly, it will return:

PONG

If you receive a connection error, Redis may not be running or listening on the correct port.


Step 3: Verify Redis Configuration

Open the Redis configuration file.

Typical location:

/etc/redis/redis.conf

Check the following settings.

Redis Port

port 6379

Bind Address

bind 127.0.0.1

Protected Mode

protected-mode yes

Incorrect settings may block WordPress from connecting.

Restart Redis after making changes:

sudo systemctl restart redis

Step 4: Check WordPress Redis Settings

Open your WordPress configuration file:

wp-config.php

Look for Redis configuration lines such as:

define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);

Ensure that:

  • Host matches Redis server address
  • Port is correct
  • No typing errors exist

Save the file and reload your website.


Step 5: Restart PHP-FPM

Redis works with PHP through extensions.

If PHP-FPM crashes, the Redis connection may fail.

Restart PHP-FPM using:

sudo systemctl restart php8.1-fpm

Replace the PHP version if necessary.


Step 6: Check Redis PHP Extension

WordPress requires the Redis PHP extension.

Verify it using:

php -m | grep redis

If Redis does not appear, install it:

sudo apt install php-redis

Restart PHP afterward.


Step 7: Check Firewall Rules

If Redis runs on another server or container, firewall rules may block it.

Check firewall status:

sudo ufw status

Allow Redis port if needed:

sudo ufw allow 6379

Be cautious when opening Redis to external connections for security reasons.


Step 8: Disable and Re-enable Redis Plugin

Sometimes the WordPress Redis plugin becomes corrupted.

Fix this by:

  1. Login to WordPress dashboard
  2. Go to Plugins
  3. Deactivate Redis Object Cache
  4. Activate it again

Then reconnect Redis.


Step 9: Flush Redis Cache

Corrupted Redis cache data may cause connection issues.

Run:

redis-cli flushall

This clears all cached data.

Your website will rebuild cache automatically.


Step 10: Check Server Resources

Redis requires sufficient memory.

If the server runs out of memory, Redis may stop responding.

Check memory usage:

free -m

If RAM is limited, consider upgrading your server.


Best Hosting for WordPress Redis Performance

High-traffic WordPress websites benefit greatly from Redis caching.

Managed cloud hosting platforms configure Redis automatically for optimal performance.

For example, Cloudways managed hosting offers:

  • built-in Redis support
  • optimized server stacks
  • automatic scaling
  • performance monitoring

You can explore their platform here:

Using a managed environment reduces server configuration errors and improves site performance.


Preventing Redis Errors in WordPress

Once Redis is working correctly, follow these best practices to avoid future problems.


Monitor Redis Service

Check Redis regularly using:

systemctl status redis

Monitoring helps detect crashes early.


Limit Redis Memory Usage

Redis stores data in memory, so it’s important to limit memory usage.

Example configuration in redis.conf:

maxmemory 256mb
maxmemory-policy allkeys-lru

This ensures Redis does not consume excessive RAM.


Keep Redis Updated

Regular updates include performance improvements and security patches.

Update Redis using:

sudo apt update
sudo apt upgrade redis-server

Use Persistent Storage

Redis can store data on disk to prevent data loss.

Enable persistence in redis.conf.


When to Contact Hosting Support

If Redis still refuses connections after trying all troubleshooting steps, contact your hosting provider.

Provide them with:

  • Redis logs
  • server configuration
  • WordPress Redis plugin details

Server engineers can identify deeper issues such as network restrictions or container problems.


Conclusion

Redis is an excellent tool for improving WordPress performance by reducing database queries and speeding up page loading.

However, configuration issues may cause the Redis connection refused error in WordPress.

Most problems occur because of:

  • Redis service not running
  • incorrect WordPress configuration
  • firewall restrictions
  • missing PHP Redis extension

By following the troubleshooting steps in this guide, you can quickly restore Redis caching and ensure your WordPress site runs efficiently.


SEO Setup

Focus Keyword

Fix Redis connection refused WordPress

Category

WordPress Errors

Tags

redis wordpress error
redis connection refused
wordpress redis caching
redis troubleshooting wordpress

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *