Every WordPress page load runs dozens to hundreds of database queries for options, posts, menus, user data and plugin settings. WordPress caches those results in memory — but only for the current request. A persistent object cache stores them in Redis between requests, so repeated lookups skip MySQL entirely.

The benefit is biggest where page caching can’t help: the admin dashboard, logged-in users, WooCommerce carts and checkout, membership sites, and AJAX-heavy plugins.

1. Install Redis

sudo apt update
sudo apt install -y redis-server php-redis
sudo systemctl restart php8.3-fpm      # load the PHP extension (adjust the version)
redis-cli ping                         # PONG

Set a memory limit and eviction policy suited to a cache in /etc/redis/redis.conf:

maxmemory 256mb
maxmemory-policy allkeys-lru
sudo systemctl restart redis-server

Keep Redis bound to 127.0.0.1 (the default). More on setup and security in installing Redis on Ubuntu.

Optional: Unix socket (slightly faster)

In redis.conf:

unixsocket /run/redis/redis-server.sock
unixsocketperm 770

Add the PHP-FPM user to the redis group so it can use the socket: sudo usermod -aG redis www-data, then restart Redis and PHP-FPM.

2. Configure wp-config.php

Add before “That’s all, stop editing!”:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
// or with a socket:
// define( 'WP_REDIS_SCHEME', 'unix' );
// define( 'WP_REDIS_PATH', '/run/redis/redis-server.sock' );

define( 'WP_REDIS_DATABASE', 0 );        // 0–15, different per site
define( 'WP_REDIS_PREFIX', 'example_' ); // unique per site
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
// define( 'WP_REDIS_PASSWORD', 'secret' );   // if Redis requires auth

Several sites on one server must not share cache keys: give each a unique WP_REDIS_PREFIX (and optionally its own database number). Otherwise one site can read another’s cached options — with confusing and sometimes serious results.

3. Install the plugin and enable the cache

With WP-CLI:

cd /var/www/example.com
sudo -u www-data wp plugin install redis-cache --activate
sudo -u www-data wp redis enable
sudo -u www-data wp redis status

wp redis enable copies an object-cache.php drop-in into wp-content/. That file is what actually routes WordPress’s cache calls to Redis.

In wp-admin, Settings → Redis shows the status: “Connected”, plus hit ratio and memory once traffic flows.

4. Verify it works

redis-cli monitor | head -20      # watch keys being read/written while you load pages (Ctrl+C to stop)
redis-cli info stats | grep -E 'keyspace_hits|keyspace_misses'
redis-cli --scan --pattern 'example_*' | head

A hit ratio above ~80–90% after warm-up is typical. Measure the difference with the Query Monitor plugin: database queries per admin page should drop sharply.

5. Object cache vs page cache

They solve different problems — use both:

Page cache Object cache (Redis)
Caches Entire HTML pages Results of individual queries/computations
Helps Anonymous visitors Logged-in users, admin, dynamic pages
Examples Nginx FastCGI cache, WP Rocket, LiteSpeed Cache Redis Object Cache, Object Cache Pro

See caching layers compared.

6. Things to watch

  • Large autoloaded options still need to be transferred from Redis on every request; clean them up — see autoloaded options.
  • Stale data after direct database edits. If you change data in MySQL directly (or import a database), flush the cache: wp cache flush.
  • Redis restarts empty the cache (fine — it rebuilds). If Redis becomes unreachable, the plugin falls back to no persistent cache; the site keeps working, just slower.
  • Eviction: if evicted_keys climbs quickly, raise maxmemory.

7. Disable or remove

sudo -u www-data wp redis disable      # removes the drop-in
sudo -u www-data wp plugin deactivate redis-cache

If a broken drop-in breaks the site, delete wp-content/object-cache.php directly.

Is it worth it?

For a small blog behind a page cache, the gain is modest. For WooCommerce, membership sites, LMS platforms, busy admin teams or multisite networks, an object cache is one of the most effective optimisations available — and on a VPS you control Redis yourself at no extra cost.

More performance work: WordPress performance optimization and WooCommerce performance. Our WordPress VPS plans have the RAM to run Redis alongside PHP and MySQL.

  • WordPress
  • Redis
  • Performance