Install Redis caching engine on cPanel server

 Class 'Redis' not found


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.

Installation Procedure

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.

Copy to Clipboard

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.

Copy to Clipboard

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.

Copy to Clipboard

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.

Copy to Clipboard

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

Copy to Clipboard


make all optional as no otherwise install fails


enable igbinary serializer support? [no] : no

enable lzf compression support? [no] : no

enable zstd compression support? [no] : no


successful install message


Build process completed successfully

Installing '/opt/cpanel/ea-php74/root/usr/lib64/php/modules/redis.so'

install ok: channel://pecl.php.net/redis-5.3.7

Extension redis enabled in php.ini

systemctl restart httpd


Now we can see the PHP Redis extension is enabled by running below PHP extension list verification command.

Copy to Clipboard

Okay, this concludes the php-redis extension install in the server. Now lets proceed with the next section.

Configure WordPress

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.

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation