Install Redis persistent object caching on dedicated server

How to easily install and use Redis object caching on a dedicated server from WHM

Speed is crucial to website performance and ranking and caching is among the most critical things to speed up your WordPress website. Bloggers generally use cache plugins like WP Rocket, WP Supercache or W3TC to cache WordPress. However, you may also sometimes notice a warning on your site health dashboard that your site can benefit from persistent object caching. If you have used W3TC on your blog, then there is a section in it named Object Cache. In this case, the users who do not have a persistent object cache installed on their server have to depend on disk for object caching. You will see two more options for object cache at the bottom including Memcached and Redis. In several cases, caching to disk for object cache in W3TC is not recommended. It is better to install Redis or Memcached both of which improve WordPress performance. You need just any one of the two on your server. In this post, we will discuss how to install and enable Redis persistent object caching on your dedicated server.

What is object caching and why object caching?

Object caching is a server side caching or a type of caching that happens at the server level unlike the regular caching methods we use. It stores the database query results that have been loaded and then loads them from the cache when requested by a user next time. In this way, the database does not need to be queried again and again and responses are served to clients faster. WordPress also has a built in object cache then why would anyone need a persistent object cache like Redis. Here is what WordPress says about its built in object cache:

By default, the object cache is non-persistent. This means that data stored in the cache resides in memory only and only for the duration of the request. Cached data will not be stored persistently across page loads unless you install a persistent caching plugin.

WordPress object cache

The built in object cache in WordPress is inefficient since the cached data is not stored for longer than a single page load. So, if you want to reduce the load on your database, you must install a persistent object cache solution like Redis. In this way, object cache will store cached data for all the subsequent page loads reducing the burden on the database.

You will not need object cache on a static website. However, on a dynamic site that loads tons of data across hundreds or thousands of pages and stores this data in the database like user data, taxonomies, links, SEO data and other types of data, it sends one or several database queries each time it loads a page. This will lead to higher burden on the database since it will be queried once or several times each time a page loads. If you use object cache this will not happen since the data is stored in cache and can be displayed within a flash when a client requests. Note that retrieving content from cache is much faster compared to querying the database. If you query the database each time, it will lead to slower loading pages but if you provide the response from the data stored in the cache, WordPress pages will load faster. Another important advantage of using object cache is that your server resources are utilized efficiently. If your site is experiencing traffic growth, you must definitely consider using object cache for faster page load times.

How to install Redis persistent object cache on WHM/Cpanel server

There are many hosts that include Redis cache with their hosting plans. They may offer one click installation with managed WordPress plans for VPS or dedicated servers. Otherwise, you can always install manually. However, before you install Redis, I will suggest you to check your php version and upgrade to the latest. Php 8.2 has been released and you can add it to your account or at least upgrade to 8 or 8.1.

To install Redis on your server, all you need to do is to install it from PHP PECL and add an apache module named mod_socache_redis.

To start the installation process, you need to login to WHM as root user. Now search for Module Installers. You can find module installers under the software section in WHM. Click to enter. Inside the module installers dashboard, you will see four options. The one we are concerned with is PHP PECL. Check the image below.

Module installers.

Now, click on manage before PHP PECL. Enter the PHP PECL and search for Redis in the search box. You can also select to show all the available modules. Searching for Redis will bring up the Redis module. You have to click install.

The installation process will last only a few minutes and you will see it in the output on your screen that Redis is being installed from PHP PECL.

Once Redis has been installed through PHP PECL, the only remaining task is to install mod_socache_redis. Search for EasyApache 4 in WHM and click on it. It will take you to a list of profiles. Check out your currently installed profile (which must be showing at the top with the currently installed packages) and click on customize. Click on the apache modules on the left and then search for Redis in the search box that appears. The results will show mod_socache_redis. Toggle the button next to it and then go to review on the left. At the end of the process, click on provision. The provisioning process lasts a few minutes only and then the process of installing Redis persistent object cache on your server is complete.

You can use the following command in WHM -> terminal to restart redis:

sudo systemctl restart redis

In the WHM, you can restart http server (apache) by searching for restart services.
Go to your WordPress installation. If you are using W3TC, you will see after restarting your server that the Redis option under object cache and database cache has been activated. You can select Redis for object cache. Otherwise, if you are using WP Rocket, you can use the Redis Object cache plugin. Install it from WordPress plugin repository and then activate it. Now, enable object cache from the settings. After enabling, you will see something like this on your dashboard.

You can also check if Redis is running from the terminal using this command.

redis-cli ping

When you enter this command you will get the following response:

PONG

which means Redis is active and running on your server. Check the status from terminal using the following command

sudo systemctl status redis

This will show you the status. You will see something like the image below in terminal.

Note that Redis is active and running in the image above (highlighted in green). Status: “Ready to accept connections”.