What is Redis?

Redis is an in-memory data structure store. It can work as a database, cache mechanism, etc.

Any WordPress website stores all its data in a database. For loading a webpage, it runs a database query via PHP scripts.

With Redis running on a server, it stores these queries into system memory. As a result, when another user accesses the same page, it retrieves the results from the memory. In other words, there is no need to make a database query again. Thus, it saves time and improves website performance as such.

In this guide, we will be installing Redis on a Ubuntu server. The commands are the same for Debian.


Begin by logging onto your WordPress site via SSH:

Once logged in, update your server and install Redis:

apt-get update
apt-get install redis-server php-redis

After the install completes, verify that Redis has installed and is listening on port 6379:

redis-server --version

Verify that Redis is listening on port 6379:

netstat -lpan | grep :6379

We now need to configure the Redis configuration file.

Add the following lines to /etc/redis/redis.conf

maxmemory 256mb
maxmemory-policy allkeys-lfu

Before these changes come into effect, you will need to restart Redis and PHP:

systemctl restart redis-server
systemctl restart php7.2-fpm

WordPress Configuration

We will need to add the cache variables into our WordPress configuration file found at /var/www/html/wordpress/wp-config.php – your installation path may vary.

define( 'WP_CACHE_KEY_SALT', 'yourdomain.com' );
define( 'WP_CACHE', true );

Enabling the Redis Plugin for WordPress

  1. Head to Plugins – Add New
  2. Search for Redis Object CacheInstall and then Activate
  3. Redis settings will now be available under the general Settings tab – open it
  4. Enable Redis and if all works it will say “Connected”

That’s it! Redis Object Cache is now installed and enabled. You can test your site loading speeds on various sites such as gtmetrix.com and pingdom.com

Tagged in:

, ,

About the Author

Pauraic Morrissey

Born and bred Irishman with a slight obsession with everything IT.

View All Articles