Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Configure Redis Caching for WordPress

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Redis caching can dramatically speed up your WordPress site by storing database query results and rendered pages in memory, reducing server load and improving response times. This guide walks you through installing and configuring Redis on a typical Linux server with WordPress, assuming you have SSH access and basic command-line comfort.

What You'll Need

  • WordPress site (self-hosted, not WordPress.com)
  • SSH access to your server (root or sudo privileges)
  • A Linux server (Ubuntu/Debian or CentOS/RHEL examples shown)
  • PHP installed with the command-line interface (php-cli)
  • Ability to edit files via nano, vim, or an FTP client

Step-by-Step

  1. Install Redis Server
    On Ubuntu/Debian: sudo apt update && sudo apt install redis-server
    On CentOS/RHEL: sudo yum install redis
    Check the version with redis-server --version.
  2. Start and Enable Redis
    Run sudo systemctl start redis and sudo systemctl enable redis to start it now and on boot. Verify with redis-cli ping – it should return PONG.
  3. Install the PHP Redis Extension
    This extension lets PHP talk to Redis. On Ubuntu/Debian: sudo apt install php-redis
    On CentOS/RHEL: sudo yum install php-pecl-redis
    After installation, restart PHP-FPM or Apache: sudo systemctl restart php7.4-fpm (adjust version) or sudo systemctl restart apache2.
  4. Verify the Extension is Loaded
    Run php -m | grep redis – you should see redis in the output. If not, check that the extension path is correct in php.ini.
  5. Install a WordPress Redis Plugin
    From your WordPress admin dashboard, go to Plugins → Add New and search for “Redis Object Cache”. Install and activate it. Alternatively, download the plugin from the WordPress repository and upload it manually.
  6. Configure the Plugin
    After activation, go to Settings → Redis. The plugin will attempt to connect using default settings (localhost, port 6379). If your Redis is on a different host or port, update the WP_REDIS_HOST and WP_REDIS_PORT constants in your wp-config.php file.
  7. Enable Object Caching
    In the plugin settings page, click the Enable Object Cache button. The plugin will write the necessary configuration to wp-content/object-cache.php. You should see a green status message confirming Redis is connected.
  8. Test the Cache
    Visit your site a few times, then check the Redis stats in the plugin dashboard. You should see cache hits increasing. You can also run redis-cli monitor to see live queries being served from Redis.
  9. Optional: Configure Page Caching
    For full-page caching, use a plugin like W3 Total Cache or WP Super Cache alongside Redis. In W3 Total Cache, go to Performance → General Settings, set Page Cache Method to “Redis”, and enter your server details.
  10. Set Up Redis Persistence (Optional)
    By default, Redis saves data to disk periodically. For better durability, edit /etc/redis/redis.conf and adjust the save directives. Restart Redis after changes.

Common Mistakes

  • Forgetting to restart PHP after installing the extension – the extension won’t load until PHP is restarted.
  • Using the wrong Redis host/port – if Redis is on a different server, you must update the constants in wp-config.php, not just the plugin settings.
  • Not enabling object caching – installing the plugin alone does nothing; you must click the “Enable” button.
  • Running Redis on a public IP without a password – this exposes your cache to the internet. Always bind to localhost or set a strong password.
  • Mixing incompatible caching plugins – using multiple object cache plugins can cause conflicts. Stick to one.

Tips

  • Monitor memory usage – Redis uses RAM. Set a maxmemory limit in redis.conf (e.g., maxmemory 256mb) and choose a policy like allkeys-lru to evict old keys.
  • Use a Unix socket instead of TCP – for local setups, connecting via socket is faster. Add WP_REDIS_SCHEME and WP_REDIS_PATH to wp-config.php.
  • Flush cache after major updates – when you update plugins or themes, clear the Redis cache to avoid stale data.
  • Consider Redis for sessions – if you run a membership site, storing PHP sessions in Redis can improve performance.
  • Backup your Redis data – if you enable persistence, include Redis dumps in your backup routine.

Troubleshooting

  • Plugin shows “Connection refused” – Check if Redis is running: sudo systemctl status redis. If it’s not, start it. Also verify the host/port in wp-config.php.
  • Redis extension not loading – Run php -v to see if the extension is compiled. If not, reinstall php-redis and restart PHP again. Check that extension=redis.so is in your php.ini.
  • Site becomes slow after enabling – This usually means Redis is not actually caching (hits are low). Check the plugin stats; if misses are high, ensure object caching is enabled and that your site isn’t using a page cache that bypasses it.
  • Redis uses too much memory – Set a maxmemory limit and choose an eviction policy. Use redis-cli info memory to see usage.
  • Changes don’t take effect – Clear the Redis cache via redis-cli flushall and also clear any page cache plugin. Sometimes you need to wait a minute for cron jobs to refresh.

Frequently Asked Questions

Do I need Redis if I already have a caching plugin?

Most caching plugins like W3 Total Cache or WP Super Cache handle page caching, but they don’t cache database queries efficiently. Redis adds object caching, which reduces database load significantly, especially on dynamic sites.

Will Redis work on shared hosting?

Usually not, because shared hosts don’t allow you to install Redis server or the PHP extension. You need a VPS or dedicated server.

Is Redis safe for a production site?

Yes, but you must secure it: bind to localhost, set a password, and use a firewall. Also configure persistence to avoid data loss on restart.

Can I use Redis with a CDN?

Absolutely. CDNs cache static assets, while Redis caches dynamic content. They complement each other.

What if my WordPress site is on Windows?

Redis officially supports Linux and macOS. On Windows, you can use a Docker container or a third-party port, but it’s not recommended for production.

How do I know Redis is actually speeding up my site?

Use a tool like Query Monitor to see database query times before and after. You can also check Redis hit rate in the plugin dashboard – a high hit rate (above 90%) indicates good performance.