Redis is an open source in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.
Many PHP applications are required the PHP Redis extension. Today we will see how to install PHP Redis on a CentOS/cPanel server. Notable that we are installing on CentOS/RHEL 7.x.
At first, we will install Remi repository. Login to your server as root and enter the following command:
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Now enter the following commands to install, enable and start the Redis:
yum -y install redis –enablerepo=remi –disableplugin=priorities
systemctl enable redis
systemctl start redis
Redis has installed and running now. We can verify it entering the following command:
systemctl status redis
Now will install PHP Redis extension. Copy the entire command and paste the command on terminal. The command will install the PHP Redis extension for PHP-7.0 and all earlier versions.
for phpver in $(whmapi1 php_get_installed_versions|grep -oE ‘\bea-php.*’) ; do cd ~; wget -O redis.tgz https://pecl.php.net/get/redis; tar -xvf redis.tgz; cd ~/redis* || exit; /opt/cpanel/”$phpver”/root/usr/bin/phpize; ./configure –with-php-config=/opt/cpanel/”$phpver”/root/usr/bin/php-config; make clean && make install; echo ‘extension=redis.so’ > /opt/cpanel/”$phpver”/root/etc/php.d/redis.ini; rm -rf ~/redis*; done
Once the installation process is completed, enter the following commands to restart Apache and PHP:
/scripts/restartsrv_httpd
/scripts/restartsrv_apache_php_fpm
Once the Apache & PHP restart is completed, enter the following command to verify your installation. Copy the entire command and paste on terminal:
for phpver in $(whmapi1 php_get_installed_versions|grep -oE ‘\bea-php.*’) ; do echo “PHP $phpver” ; /opt/cpanel/”$phpver”/root/usr/bin/php -i |grep “Redis Support”; done
You will like the following:
You also can verify the installation using the command for any individual PHP version. For example, here I have used PHP 7.0:
/opt/cpanel/ea-php70/root/usr/bin/php -m | grep redis
Here is the output of the command:
If you need to install PHP Redis extension for any lower version of PHP such as PHP5.5, PHP5.6 etc, then enter the following command. Copy the entire command and paste on terminal:
for phpver in 55 56 70 ; do cd ~; wget https://pecl.php.net/get/redis-3.1.0.tgz; tar -xvf redis-*.tgz; cd redis*; /opt/cpanel/ea-php$phpver/root/usr/bin/phpize; ./configure –with-php-config=/opt/cpanel/ea-php$phpver/root/usr/bin/php-config; make && make install; echo ‘extension=redis.so’ >> /opt/cpanel/ea-php$phpver/root/etc/php.d/redis.ini; cd ~; rm -rf redis*; done
Again, restart your Apache Web Server and PHP by entering the following commands:
/scripts/restartsrv_httpd
/scripts/restartsrv_apache_php_fpm
Now, again verify your installation entering the following command. Copy the entire command and paste on terminal:
for phpver in $(whmapi1 php_get_installed_versions|grep -oE ‘\bea-php.*’) ; do echo “PHP $phpver” ; /opt/cpanel/”$phpver”/root/usr/bin/php -i |grep “Redis Support”; done
The output of command will be like the following:
The PHP Redis extension is completed.
Leave A Comment?