Redis Cache Setup for WordPress on CentOS with cPanel

Redis cache
In this article, TNP HOST will demonstrate installation of Redis cache for WordPress and how to supercharge your website using Redis.redis cache for wordpress

One of the most popular caching systems is Redis. This article explains how to improve WordPress performance by using Redis Cache. There are several articles available on internet related to use of Redis in pure Ubuntu or CentOs. However, Redis is fully compatible with cPanel/WHM installation and you can use the below guide to install Redis on cPanel/WHM VPS or a Dedicated Server purchased from TNP HOST.

What is Redis Cache :

Redis is an open source (Berkeley Software Distribution ( BSD ) licensed), in-memory data structure store which is used as a database, cache and a message broker. It also supports data structures such as Sets, Hashes, Strings, Lists, Sorted sets with range queries, Hyperloglogs, Bitmaps and Geospatial indexes with radius queries.

Redis has built-in replication, LRU eviction, Lua scripting, transactions and different levels of on-disk persistence, and provides high opportunity via Redis Sentinel and automatic partitioning with Redis Cluster.

In fact, the similar result can also be achieved from Memcached, Redis is most easy to install with similar performance of cPanel/ WHM.

How does the caching work?

Every time a WordPress page is accessed a query is executed towards the WordPress database to fetch the content of the page. By implementing a Redis caching, the results of the query will be stored into the memory block managed by Redis.

Upon future requests of the same page, the information will be retrieved from the Redis cache eliminating the need to execute the MySQL query. This can be very beneficial even if you have just a few visitors as on your website as retrieving the data directly from the memory via the Redis can reduce the page load time in half.

How Redis helps WordPress:

Still, this solution is most beneficial for WordPress websites with a large number of simultaneous requests as reducing the number of simultaneous queries to your website database greatly improves the performance, eliminates MySQL bottleneck and provides better utilization of the server resources so you can handle more traffic, faster and cheaper eliminating the need for a more powerful hardware.

Additionally, caching with Redis completely terminate the need to manually flush the cache when new content is published. If a page is edited or a new content is posted on your website, the Redis cache for that content will be invalidated to avoid dirty cache and will be updated after the next page load.

Installing Redis cache, PHP-Redis and WordPress

To complete the installation steps below you will need root access to your server or a user with sudo privileges. The steps below explain the installation and configuration process on CentOS 6 with cPanel 11.48 but should work on other cPanel versions as well.

1. Install Redis Cache
You must have SSH access. Access server with SSH and download the following two rpms:

Run the following commands and this completes the Redis installation:

To start Redis automatically upon server reboot, run the following command:

2. Configure Redis
Open the Redis configuration file:

and add the following 2 lines at the end of the file:

You are always free to allow more memory for the Redis cache, change the maxmemory value to the desired value.

3. Install PHP-REDIS
Once the Redis is installed, we will need the PHP-REDIS extension. On a cPanel/WHM server you can easily install PHP-REDIS with just a few clicks. Login your server WHM and search for ‘Module Installers’ from the menu on the left.

redis for wordpress

On the Module Installers page click on the Manage link for the PHP Pecl. On the PHP Pecl Installer page search type “redis” and click the Go button.

Click on the “Install” link from the results for the Redis extension to complete the installation.

4. Configure WordPress Caching
Wordpress requires few changes to set up Redis. First, download the object-cache file and upload it under your WordPress wp-content/ directory.

Rename the file from object-cache.php.txt to object-cache.php in your wp-content/ directory. You can reconfirm the settings of this file however this file generally does not require any modifications.

Next, open your wp-config.php file and add the following lines at the end of the * Authentication Unique Keys and Salts. section:

Change the example.com with your real domain you want to host or any randomly generated string.

5. Restart Redis and Apache via SSH
To complete the setup restart the Apache and Redis for WordPress by executing:

Verify Your Setup

To verify Redis for wordpress that Redis is caching the results for your WordPress installation rung the following command via the shell:

You should see similar results to:

To exit press CTRL-C.

If you want to manually flush Redis Cache, you can run the following command


Conclusion

If you are looking for optimized WordPress Hosting solution you may review our SSD Shared hosting plans or our Cloud VPS and Dedicated Servers solutions. All TNP HOST WordPress Hosting plans are fully managed with 24/7 Technical Support so you can discuss with our experts on how to improve your WordPress website performance and get started with Redis.

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave A Comment?

This site uses Akismet to reduce spam. Learn how your comment data is processed.