WordPress asks its database the same questions on nearly every page load: the site options, the menu, the latest posts. The answers barely change between visits, yet the database computes them again each time. That is what an object cache fixes, and Redis is the usual choice for it. This guide shows you how to install Redis for WordPress object caching on your VPS, lock it down properly, and wire it into WordPress without breaking anything.
Object caching is not page caching. A page cache serves a saved HTML file and skips PHP entirely. An object cache still runs PHP, but it stores the results of database queries in memory so the same question gets an instant answer the second time. The two work together: the page cache handles anonymous visitors, the object cache speeds up everything else, including logged-in users and the admin dashboard.
What Object Caching Changes for WordPress
On a typical small site, the biggest win shows up in the admin area and on pages a page cache cannot serve, like the cart page on a shop or any page for a logged-in user. The database load drops because repeated queries never reach MySQL. Time to first byte on uncached pages often falls noticeably, though how much depends on your theme and plugins: a heavy theme with dozens of queries per page gains more than a lean one with ten.
There are limits. Redis caches database objects, not rendered HTML, so it will not fix a slow theme or a bad plugin. It also adds a moving part: if Redis goes down, WordPress falls back to the database and keeps working, just slower. On a very small site with almost no traffic, the difference may be too small to notice. Redis use cases on a VPS explains the other jobs Redis can do beyond WordPress, which helps you decide whether the install earns its memory.
Install Redis for WordPress Object Caching Step by Step
We install Redis from the Ubuntu 24.04 repositories. It is stable, it gets security updates with the rest of the system, and it is new enough for this job. A deeper look at the same install, including building from source when you need a newer version, is in our guide to installing Redis 7.x on Ubuntu 24.04.
sudo apt update
sudo apt install -y redis-server php-redis
sudo systemctl enable --now redis-server
sudo systemctl status redis-server
The php-redis package gives PHP the extension it needs to talk to Redis. If you run several PHP versions on one VPS, install the extension for each version you use, for example php8.3-redis, and restart PHP-FPM after. Confirm the connection works:
redis-cli ping
It should answer PONG. If it does not, check that the service is actually running before you touch anything else.
Check the version and memory use
redis-cli info server | grep redis_version
redis-cli info memory | grep used_memory_human
On a fresh install Redis uses only a few megabytes. That number will grow once WordPress starts filling it, which is why the memory limit in the tuning section matters.
Lock Redis Down Before You Connect WordPress
Redis has no authentication by default and, until recently, listened on every network interface. An open Redis on the internet gets found and emptied within hours. Do every step here before you connect WordPress. A secure Redis Ubuntu setup is three settings and five minutes.
Bind to localhost only
Open /etc/redis/redis.conf and confirm these lines:
bind 127.0.0.1 ::1
protected-mode yes
port 6379
Binding to localhost means only processes on this server can reach Redis. If you ever need another server to reach it, use a VPN or an SSH tunnel, not a public port.
Set a strong password
In the same file, find the requirepass line, uncomment it, and set a long random password:
requirepass your-long-random-password-here
Generate it with openssl rand -base64 32 rather than typing something memorable. WordPress will need this password in its config, so keep it somewhere safe. After saving, restart Redis and test that the password is required:
sudo systemctl restart redis-server
redis-cli ping
redis-cli -a your-long-random-password-here ping
The first ping should fail with an authentication error and the second should answer PONG. If the first one still works, the password did not take, so recheck the config file for a second requirepass line further down that overrode yours.
Close the port in the firewall
Even bound to localhost, block port 6379 at the firewall so a config mistake can never expose it:
sudo ufw deny 6379/tcp
sudo ufw status verbose
Also disable the dangerous commands. In redis.conf, rename or disable FLUSHALL and FLUSHDB so a compromised WordPress plugin cannot wipe the cache store:
rename-command FLUSHALL ""
rename-command FLUSHDB ""
Restart Redis once more after these changes.
Connect WordPress to Redis
With Redis locked down, the WordPress side takes a plugin and a few lines of config. A standard wordpress redis plugin setup uses the Redis Object Cache plugin by Till Krüss, which is free and widely used.
Install the plugin
From the WordPress admin, install and activate Redis Object Cache. Or use WP-CLI from the site root:
wp plugin install redis-cache --activate
This redis object cache wordpress setup needs no other plugin to work.
Add the connection details
Add these lines to wp-config.php, above the line that says “stop editing”:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', 'your-long-random-password-here' );
define( 'WP_REDIS_PREFIX', 'mysite:' );
The prefix matters if you run more than one WordPress site against the same Redis instance. Without it, two sites share one key space and can serve each other stale data. Give every site its own prefix.
Enable the cache
wp redis enable
wp redis status
The status output should show a connection and a hit count that climbs as you browse the site. In the admin panel, the same screen lives under Settings, then Redis. Click around the site for a minute, then refresh the status: if the hit count stays at zero, the plugin is installed but WordPress is not routing queries through Redis yet, and the usual cause is a missing object-cache.php drop-in, which the enable step normally creates.
Check That the Cache Is Working
Numbers beat feelings here. Compare time to first byte before and after with curl:
curl -o /dev/null -s -w "TTFB: %{time_starttransfer}sn" https://example.com/a-logged-in-only-page/
Run it three times and take the middle value, since the first request after a restart is always slow. A cached object answer shows up as a lower and steadier TTFB on repeat loads. If nothing changed, confirm the cache is actually being used with:
redis-cli -a your-long-random-password-here info stats | grep -E "keyspace_hits|keyspace_misses"
Hits should grow as you browse. A hit ratio above 80 percent is healthy; below that, something is writing keys that never get read again, often transients from a plugin. Our explainer on WordPress transients helps you tell the useful ones from the junk.
If TTFB did not move at all, the bottleneck may sit elsewhere. Work through the checks in our guide to fixing slow TTFB on a VPS before you blame the cache: slow PHP workers or an undersized database buffer will hide any caching gain.
Tune Memory So Redis Stays Small
Redis will use as much memory as you let it. On a 2 GB VPS, cap it at 256 MB in redis.conf:
maxmemory 256mb
maxmemory-policy allkeys-lru
The allkeys-lru policy evicts the least recently used keys when the cap is hit, so the cache degrades gracefully instead of crashing the server. WordPress can always rebuild a cache entry from the database, so eviction costs a slow page, not lost data.
Watch the real usage for a week:
redis-cli -a your-long-random-password-here info memory | grep -E "used_memory_human|maxmemory_human"
If used memory sits at the cap all day with a low hit ratio, raise the cap a little or find the plugin writing junk keys. If it never passes 50 MB, lower the cap and give the memory back to PHP or MySQL. You do not need to back up the cache itself, since it rebuilds, but keep redis.conf and your wp-config.php lines in your usual server backup.
When Object Caching Will Not Help
A site with ten visitors a day and a lean theme will not feel the difference. Redis also will not fix a slow query that runs once and never repeats, a plugin that fires hundreds of queries per page, or a database that needs an index. Fix those first, then add the cache. If your VPS has only 1 GB of RAM and already swaps under load, spend the memory on PHP and MySQL before Redis.
Done right, the setup is quiet: Redis runs, WordPress asks fewer questions of the database, and the only time you notice it is when you check the hit ratio and see the number climbing. Keep the password strong, keep the port closed, and check the memory cap once a month.