Install Redis on Ubuntu for WordPress Caching

By Anurag Singh

Updated on Jun 13, 2025

Install Redis on Ubuntu for WordPress Caching

In this tutorial, we'll learn how to install Redis on Ubuntu for WordPress caching.

Redis is a powerful in-memory data store used to speed up websites by caching data and reducing load on the MySQL database. In WordPress, enabling Redis object caching can drastically improve performance, especially for high-traffic sites. In this guide, we walk step-by-step through installing Redis on Ubuntu and configuring it with WordPress using the latest best practices.

Prerequisites

Before we begin, let’s ensure we have the following in place:

Install and Configure Redis on Ubuntu 24.04 for WordPress Caching (2025 Guide)

Step 1: Update Our System

We begin by updating the server packages to ensure we're working with the latest versions:

sudo apt update && sudo apt upgrade -y

This step is essential to avoid compatibility issues with Redis or PHP modules.

Step 2: Install Redis Server on Ubuntu

Let’s install Redis directly from Ubuntu's package manager:

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

After installation, Redis will be set up as a systemd service and will start automatically.

Step 3: Secure Redis Configuration for Production

Redis is powerful but must be secured properly. Open the configuration file:

sudo nano /etc/redis/redis.conf

Make the following changes:

Bind to localhost only (default setting):

bind 127.0.0.1 ::1

Set supervised mode to systemd:

supervised systemd

This allows Redis to integrate with AlmaLinux’s service manager.

Optional Tweaks for WordPress caching (not required but recommended for large sites):

maxmemory 256mb
maxmemory-policy allkeys-lru

These lines ensure Redis does not consume all system memory and uses LRU (Least Recently Used) eviction when full.

Save and exit. Then restart Redis to apply changes:

sudo systemctl restart redis

Step 4: Install PHP Redis Extension

WordPress uses PHP to interact with Redis. We need the PHP Redis extension:

sudo apt install php-redis -y

After installation, restart the PHP and web server services:

sudo systemctl restart php8.2-fpm
sudo systemctl restart nginx

Adjust PHP version and web server based on your setup (e.g., Apache users should restart apache2 instead).

Step 5: Verify Redis is Working

Run the following test to confirm Redis is up and responsive:

redis-cli ping

Expected output:

PONG

This confirms Redis is functioning.

Step 6: Enable Redis Object Cache in WordPress

6.1 Install a Redis Plugin

From the WordPress dashboard:

  • Go to Plugins > Add New
  • Search for "Redis Object Cache" by Till Krüss
  • Install and activate it

6.2 Enable Object Cache

Once activated, navigate to:

  • Settings > Redis

Click on Enable Object Cache

You should see a green status message like “Connected”.

 Step 7: Test Redis Object Cache Performance

To confirm Redis is caching WordPress data:

  • Navigate to your WordPress site.
  • Refresh a few pages.
  • Return to Settings > Redis.
  • Look for cache hits and uptime.

For deeper monitoring, install redis-tools:

sudo apt install redis-tools -y

Then use:

redis-cli info

Check for keyspace_hits, keyspace_misses, and memory stats.

Step 8: Configure Redis to Start on Boot

Ensure Redis service is enabled after reboot:

sudo systemctl enable redis

This guarantees Redis caching remains active after system restarts.

Step 9: (Optional) Improve Redis Performance via TTL

To control cache expiration, define a time to live (TTL) for objects. Many Redis plugins allow this or we can set it manually in wp-config.php:

define('WP_REDIS_MAXTTL', 900); // Sets object cache to expire in 15 minutes

Add this just before /* That's all, stop editing! */ in wp-config.php.

Final Notes

In this tutorial, we've learnt how to install Redis on Ubuntu for WordPress caching. We now have Redis installed, configured, secured, and integrated with WordPress for object caching on Ubuntu. This setup offloads repeated database queries, lowers response times, and improves scalability for any WordPress site.