How to Setup WordPress Caching with Redis on CentOS 6 and cPanel

Updated on Jun 11, 2019



In this guide, we will show you how to boost your WordPress performance by using Redis cache. Most guides on how to install and configure Redis with WordPress explain the process on a clean Ubuntu or CentOS installation. However, Redis is fully compatible with cPanel/WHM and in this guide we will cover the steps on how to setup Redis with WordPress on a cPanel VPS or Dedicated Server.

What is Redis?

Redis is an open-source advanced key-value cache and store. It is usually referred to as a data structure server and it is known for its outstanding performance as it works with an in-memory dataset. Despite the fact that similar results can be achieved with other cache software such as Memcached, Redis is an excellent choice and it is relatively easy to set up and configure.

Also, we will show you how to setup Redis on CentOS 6 server with cPanel, setup php-redis and perform the needed configuration settings on your WordPress installation to make it cache database queries via Redis.

How does 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.

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 of a more powerful hardware.

Additionally, caching with Redis eliminates the need to manually flush the cache when new content is published. If a page is edited or 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, 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

Access your server via SSH and download the following two rpms:



Run the following commands to complete the Redis installation:

rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

yum install –y redis

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

To make redis start automatically:

chkconfig –level 2345 redis on

2. Configure Redis

Open the Redis configuration file:

vi /etc/redis.conf

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

maxmemory 256mb

maxmemory-policy allkeys-lru

If you would like to allow more memory for the Redis cache, change the maxmemory value to the desired amount.

3. Install PHP-REDIS

After we have Redis 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 refer to ‘Module Installers’ from the menu on the left.




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




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




4. Configure WordPress Caching

Setting up WordPress to work with Redis requires just a few changes. First, download the object-cache.php.txt file and place it under your WordPress wp-content/ directory.

Rename the file from object-cache.php.txt to object-cache.php and place the file under your wp-content/ directory. You do not need to perform any modifications on the file to make it work but you may always review the settings.

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

define(‘WP_CACHE_KEY_SALT’, ‘’);

define(‘WP_CACHE’, true);

Change the with your actual domain name or any random generated string.

5. Restart Redis and Apache via SSH

To complete the setup restart the Apache and Redis by executing:

/etc/init.d/httpd restart

/etc/init.d/redis restart 

Verify Your Setup

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

redis-cli monitor

You should see similar results to:


1428089226.419271 “monitor”

1428089226.419272 “GET” “example.comwp_:options:alloptions”

1428089226.419479 “EXISTS” “example.comwp_:options:notoptions”

1428089226.419548 “GET” “example.comwp_:options:notoptions”

1428089226.419651 “EXISTS” “example.comwp_:options:alloptions”

1428089226.419729 “GET” “example.comwp_:options:alloptions”

1428089226.422514 “EXISTS” “example.comwp_:options:notoptions”

1428089226.422592 “GET” “example.comwp_:options:notoptions”

1428089226.422701 “EXISTS” “example.comwp_:options:alloptions”

1428089226.422770 “GET” “example.comwp_:options:alloptions”

1428089226.427510 “EXISTS” “example.comwp_:options:notoptions”

To exit press CTRL-C.

In case you would like to manually flush the Redis cache execute:

redis-cli flushall


Setting up Redis with WordPress on a CentOS 6 cPanel server is an easy and straight forward process that can greatly improve your WordPress performance. If you are looking for an optimized WordPress Hosting solution you may review our SSD Shared hosting plans or our Cloud VPS and Dedicated Servers solutions. All FastComet WordPress Hosting plans are fully managed with 24/7 Technical Support so you can consult with our experts on how to improve your WordPress performance and get started with Redis.

We hope you find this article useful. Discover more about FastCloud - the top-rated Hosting Solutions for personal and small business websites in four consecutive years by the HostAdvice Community!

SSD Cloud Hosting

  • Free Domain for life
  • 24/7 Technical Support
  • Fast SSD Storage
  • Hack-free Protection
  • Free Script Installation
  • Free Website Transfer
  • Free CloudFlare CDN
  • Immediate Activation
View More