How to install Redis for cPanel server

How to install Redis for cPanel server

In this short post I show how to easily install Redis and Redis PHP extensions for all PHP versions easily on a cPanel server.

Login as root and then run the below commands. These commands install the epel-release repo which provides the redis rpm. It then enables and starts the redis service after setting some needed settings. It then loops through and installs the Redis Pecl PHP extension for all currently installed PHP versions. It then loops through all PHP versions to show that the extensions are installed and enabled. It then checks via the redis-cli that its working.

yum install -y epel-release ; 
yum update -y ; 
yum -y install redis ; 
sed -i "s|^supervised no|supervised auto|" /etc/redis.conf ; 
echo "maxmemory 512mb" >> /etc/redis.conf; 
echo "maxmemory-policy allkeys-lru" >> /etc/redis.conf ; 
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf ; 
sysctl vm.overcommit_memory=1 ; 
echo never > /sys/kernel/mm/transparent_hugepage/enabled ; 
systemctl enable redis && systemctl start redis || chkconfig redis on && service redis restart; 
for version in $(ls /opt/cpanel|grep ea-php); do /opt/cpanel/${version}/root/usr/bin/pecl channel-update pecl.php.net; done; for PHP in $(ls -h /opt/cpanel |grep ea-php); do printf '\n' |/opt/cpanel/$PHP/root/usr/bin/pecl install redis; done ; 
service httpd restart; 
for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -m |grep -E 'redis'; /opt/cpanel/ea-php$phpver/root/usr/bin/php -i |grep "Redis Support"; echo ""; done; systemctl status redis||service redis status; redis-cli ping | grep --color PONG ;

“Oneliner” version. Paste in and watch it go…..

yum install -y epel-release ; yum update -y ; yum -y install redis ; sed -i "s|^supervised no|supervised auto|" /etc/redis.conf ; echo "maxmemory 512mb" >> /etc/redis.conf; echo "maxmemory-policy allkeys-lru" >> /etc/redis.conf ; echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf ; sysctl vm.overcommit_memory=1 ; echo never > /sys/kernel/mm/transparent_hugepage/enabled ; systemctl enable redis && systemctl start redis || chkconfig redis on && service redis restart; for version in $(ls /opt/cpanel|grep ea-php); do /opt/cpanel/${version}/root/usr/bin/pecl channel-update pecl.php.net; done; for PHP in $(ls -h /opt/cpanel |grep ea-php); do printf '\n' |/opt/cpanel/$PHP/root/usr/bin/pecl install redis; done ; service httpd restart; for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -m |grep -E 'redis'; /opt/cpanel/ea-php$phpver/root/usr/bin/php -i |grep "Redis Support"; echo ""; done; systemctl status redis||service redis status; redis-cli ping | grep --color PONG ;

If all went as planned it should look something like the below screenshot.

Redis Installation cPanel

Troubleshooting tips:

If Redis service fails to start there could be a couple of reasons why. I tried to account for all those reasons in the fancy commands above, but in event you hit an edge case this should point you in the right direction.

Redis log by default is located at: /var/log/redis/redis.log

If having issues and it fails to start first thing I recommend doing is checking the log via the two commands.

First is good for checking after attempting to start/restart the service and its failing.

sudo tail -n50 /var/log/redis/redis.log

This one is good if you have two ssh sessions open and want to tail the log live while starting/restarting the service.

sudo tail -f /var/log/redis/redis.log

Common issues:

Can’t handle RDB format version 9
Fatal error loading the DB: Invalid argument. Exiting.

Can’t handle RDB format version 9
Fatal error loading the DB: Invalid argument. Exiting.


This one is due to a mismatched DB file. Probably from a differing version installed from source before or higher version from an alternate repo. You can fix this by finding and removing the DB file and then restarting the service.

To find the file you can use the below. In my case it was located at: /var/lib/redis/dump.rdb

find / -name *.rdb

To remove the file: replace /var/lib/redis/dump.rdb with the filename you found from the above.

rm /var/lib/redis/dump.rdb

Then restart the service:

systemctl restart redis||service redis restart

If everything failed or you just want to easily uninstall everything from the above the below command will remove redis and all PHP extensions easily.

yum remove -y epel-release redis ;yum clean ; yum update -y ; systemctl disable redis && systemctl stop redis || chkconfig redis off && service redis stop; for PHP in $(ls -h /opt/cpanel |grep ea-php); do printf '\n' |/opt/cpanel/$PHP/root/usr/bin/pecl uninstall redis; done ; service httpd restart; for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -m |grep -E 'redis'; /opt/cpanel/ea-php$phpver/root/usr/bin/php -i |grep "Redis Support"; echo ""; done

We hope you enjoyed this post and got Redis installed quickly without issues.


I also highly recommend up voting this feature request regarding a Redis per user interface in the cPanel.

Item added to cart.
0 items - $0.00