You might already be well aware of the different caching mechanism employed on a WordPress website to serve the content to the viewer in minimum time. Most of them are file-based caching solutions and sometimes they won’t be enough to optimize the website in its best possible way. Since WordPress is s a database driven CMS its common knowledge that the database plays an important role in its working. So, optimizing the database queries can also optimize the website performance. The Redis object cache is the perfect candidate for this.

The website sends a query to the database to fetch the latest data every time a visitor accesses a certain page or link. WordPress does many such MySQL query lookups, which can slow down the website when you get lots of traffic. In such a scenario, Redis (Remote Dictionary Server) cache can act as a buffer in between the client and server as it is essentially a memory-based key-value pair database which stores all frequently accessed key-value data in the memory/RAM. Usage of RAM will make it much faster compared to old SATA disks or SSDs. This is what makes Redis a swift-caching solution for CMS such as WordPress.

Here we are setting up a Redis object cache that will help us to optimize WordPress database usage. Redis object will be used to store the cache of request for a particular query sent to the MySQL service/server. The Redis will then serve the request output from the object cache instead of hitting the MySQL server when other users try to access the same post or same article. As you can see that this can eliminate frequent database calls and round trips of to-and-from communication to the database server which will significantly enhance the server response time and site speed.

Let us start by installing the redis cache on the server. In this tutorial, we are assuming you have root access to a CentOS or AlmaLinux VPS or dedicated server (for any other OS like Ubuntu/Debian, you can use apt to install the same package but do verify the package name) to perform this action and have a WordPress instance ready to setup with redis.

If it’s a CentOS or AlmaLinux based VPS, run this command:

yum install redis

Once it is installed successfully you should make sure to start the service and make it autostart on next server boot/reboot, for this run the following commands:

systemctl start redis
systemctl enable redis

To verify the service is configured properly, run:

systemctl status redis

and you will see something similar to the following:

Here we are interested in the last line where the port on which the redis service is listening will be displayed, that is 6379 in this case.

Next install a PHP extension named php-pecl-redis which will allow WordPress to access the Redis key-value store

yum install php-pecl-redis

Now the redis installation section is complete, next we have to link the WordPress instance with the redis service. To make this possible, we can use a WordPress plugin called Redis Object Cache which can be simply searched and installed directly from the plugin page, for more details check Redis Object Cache – WordPress plugin |

Once you activate the plugin you might be greeted by a page similar to the one below:

Just click on the Enable Object Caching and you have successful linked WordPress with redis cache. So, the final output will look like this:

Please note that the plugin automatically detected the redis service on the default port 6379 in this case, if you have a different redis configuration then you have to manually enter the details in the plugin to connect.

Now that you have successfully configured the redis service, let’s check if it’s working as intended. Run the following command in the terminal or shell and casually browse through the admin dashboard:

redis-cli monitor

As you go through each WordPress page you will see some cache hits on the terminal which might look like this:

You have now successfully enabled Redis caching on your WordPress website. Congratulations!

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Reseller Hosting
Create your new income stream today with a reseller account
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.

Leave a comment

Your email address will not be published. Required fields are marked *