Redis is an open source, in-memory data structure store, used as a database, cache and message broker that can be used as a drop-in caching back-end for your Drupal or WordPress website. Its similar like Memcache. If you have a question in mind like which Caching system is best Memcache or Redis, I would say its hard to tell, Both caching systems have their own Advantages. Its up to you which one you would like to use and what kind of configuration setup better suits your environment. Normally Webmasters use Redis as caching module and there by improve the site loading time of websites. There is no in house option like cPanel Redis plugin at this moment. We need to install the Redis caching server manually on a cPanel based server. Today we discuss further on it.
How does the Redis caching works
Most website frameworks like WordPress use the database to cache internal application “objects” which can be expensive to generate (menu trees, filter results, etc.), and to keep cached page content. Since the database also handles many queries for normal page requests, it is the most common bottleneck causing increase load-times. Redis provides an alternative caching back-end, taking that work off the database, which is vital for scaling to a larger number of logged-in users. This is achieved by storing the query results as memory blocks.
Advantage of Redis
Caching with Redis will not have the need to manually flush the cache when new content is published. Additionally if a page or blog post edited, the Redis cache for that content will be invalidated and will the updated content after the next refresh of page.
The Redis daemon and Redis PHP Extension is the one we need to install for using Redis cache for our Websites. To complete the installation steps below you will need root access to your server. So if you don’t have a root access to the server, get it before proceed further. We installed Redis on Centos 7 Operating System along with Latest cPanel version. The same step will work for Centos 8 Operating Systems.
Section 1. Installing the Redis daemon
In this section we are installing Redis server package in our cPanel server. For that first log into your cPanel server over ssh terminal as root user. After that Issue below commands.
Now we have successfully installed and started the Redis service in the server. After that we can confirm the Redis is running in the server by issuing the below command.
After that in order to make sure Redis daemon is responding fine, we can run command “redis-cli ping”. If you get result “PONG”, that shows Redis is working. So lets issue the below command in our ssh terminal and here we can see the response as pong in the ssh terminal itself. Which confirms that the install Redis server package is fine.
At this point the Redis caching server is up and running on our server. Normally the configuration file of Redis located at /etc/redis.conf. We can add the following 2 lines at the end of the file for setting a memory limit for Redis install. So set this value as per your desire and system environment. In this example I am setting the value as 512Mb. After editing the file make sure to restart the Redis service in the server.
Section 2. Install PHP Redis extension
Without Redis php extensions our websites won’t be able to communicate with our Redis server installed. So use following commands for installation of php Redis extension. Here I am assuming that, our website is using the php version either 7.4 or 8.0. If your website php version is different, change the pecl binary location accordingly as per your environment.
While running the below command, we will be asked to enable below options. Its fine we leave the default option by hitting enter button.
In the “enable igbinary serializer support”? leave the default option just hit enter
in the enable lzf compression support? leave the default option and hit enter
in the enable zstd compression support? leave the default option and hit enter
Now we can see the PHP Redis extension is enabled by running below PHP extension list verification command.
Okay, this concludes the php-redis extension install in the server. Now lets proceed with the next section.
In this section we Install the “Redis-object-cache” plugin on our WordPress website. So Lets see how can integrate the installed Redis cache server with our wordPress website using WordPress plugin named ” Redis-object-cache”. Then only the caching will work for our WordPress websites. If your website is not WordPress use corresponding code or plugins available for integration. So follow coming up method if you have WordPress Website otherwise use codes which is suitable for your websites.
- So first log in to the wp-admin area of our website.
- From wp-admin area left panel, under plugins section click add new option
- Now search a plugin named “Redis Object Cache”
- The “Redis Object Cache” plugin will show up and click install now button.
- After that, click activate button
- Now we will automatically redirected to settings >> Redis section.
- From there use enable object cache option.
Now we will see the status message as Connected. Which means that, our WordPress website is successfully connected to our Redis server. This completes the install of Redis cache plugin through wp-admin area which is straight forward method.
In order to test whether the WordPress install is cached by WordPress, issue “redis-cli monitor” command over SSH and click any link in the wp-admin area. The result should be like below. It means we can see log entries appear and that conclude WordPress is communicating with Redis.
Okay, This concludes a normal install of Redis Cache on a cPanel server. I hope this article is informative. Leave your thoughts at the comment box.
I would just add the following command after installation, to make Redis start automatically on server restart:
chkconfig –level 2345 redis on
I tried following this guide and while most of it was simple i drew an error when installing redis for php
checking build system type… Invalid configuration `install’: machine `install-unknown’ not recognized
configure: error: /bin/sh /root/tmp/pear/redis/build/config.sub install failed
ERROR: `/root/tmp/pear/redis/configure –with-php-config=/opt/cpanel/ea-php74/root/usr/bin/php-config –enable-redis-igbinary=/opt/cpanel/ea-php80/root/usr/bin/pecl install redis –enable-redis-lzf=no –enable-redis-zstd=no’ failed
how do i correct this
looks like your system doesn’t have /bin/sh path