The phpredis extension provides an API for communicating with the Redis key-value store. This Redis client implements most of the latest Redis API. One can use php-redis to talk with Redis server or cluster. This page provides instructions on how to install and configure the phpredis on CentOS 8 or RHEL 8 for PHP version 7.4.
Install phpredis on CentOS 8
Let us see all commands in details.
Step 1. Install yum utils
First, we need to install yum-utils CLI compatibility layer package, type the yum command:
sudo yum update
sudo yum install yum-utils
Sample outputs:
Last metadata expiration check: 0:26:29 ago on Sat Feb 15 18:56:33 2020. Dependencies resolved. =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: yum-utils noarch 4.0.8-3.el8 BaseOS 64 k Installing dependencies: dnf-plugins-core noarch 4.0.8-3.el8 BaseOS 62 k python3-dateutil noarch 1:2.6.1-6.el8 BaseOS 251 k python3-dnf-plugins-core noarch 4.0.8-3.el8 BaseOS 193 k python3-six noarch 1.11.0-8.el8 BaseOS 38 k Transaction Summary =============================================================================== Install 5 Packages Total download size: 608 k Installed size: 1.3 M Is this ok [y/N]: y
Step 2 – Enable and install EPEL repo on CentOS 8
You need EPEL repo to install redis releated files. So turn it on, run:
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Update and check for epel repo, run:
sudo yum -y update
Step 3 – Install remi repo for PHP 7.4 and php74-php-pecl-redis5
Execute the following commands:
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo yum -y update
Sample outputs:
Last metadata expiration check: 0:33:06 ago on Sat Feb 15 18:56:33 2020. remi-release-8.rpm 29 kB/s | 20 kB 00:00 Dependencies resolved. =============================================================================== Package Architecture Version Repository Size =============================================================================== Installing: remi-release noarch 8.0-4.el8.remi @commandline 20 k Installing dependencies: epel-release noarch 8-5.el8 extras 22 k Transaction Summary =============================================================================== Install 2 Packages Total size: 42 k Total download size: 22 k Installed size: 43 k ....
Step 4 – Set default PHP version
CentOS 8 offers various PHP versions using stream and we can see all versions with the following command:
sudo yum module list php
Let us use PHP 7.4.xx as it is supported until Noverber 2021. Run the following two commands to enable php version 7.4
sudo -y yum module reset php
sudo yum -y module enable php:remi-7.4
Sample outputs:
Last metadata expiration check: 0:04:41 ago on Sat Feb 15 19:30:48 2020. Dependencies resolved. =============================================================================== Package Architecture Version Repository Size =============================================================================== Enabling module streams: php remi-7.4 Transaction Summary =============================================================================== Complete!
Step 5 – Search for phpredis packge on CentOS 8
Now we have everything set up correctly on CentOS Linux 8 server. It is time to see what packages offered, run:
sudo yum search php-pecl-redis
sudo yum search php-pecl-redis5
Sample outputs:
============================== Name Exactly Matched: php-pecl-redis5 ============================== php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store ================================== Name Matched: php-pecl-redis5 ================================== php70-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store php71-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store php72-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store php73-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store php74-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store
Step 6 – Installing phpredis on CentOS 8
For PHP version 7.4, we need to install the php74-php-pecl-redis5 (or php-pecl-redis5 which is selected by default when we enabled ‘php:remi-7.4’ stream ) package as follows:
sudo yum install php-pecl-redis5
Of course, you can install nginx or apache along with other PHP 7.4 modules if not installed on the server:
sudo yum install php-fpm php-common php-cli nginx php-mysqlnd php-pecl-redis5
Step 7 – Restart PHP or Nginx/Apache server
It depends upon your configuration, and you need to restart the Apache 2 or restart PHP-fpm service or restart/reload the Nginx service. Since I am using php-fpm as FastCGI process manager, I am going to use the following systemctl command:
sudo systemctl restart php-fpm.service
## OR ##
sudo systemctl reload php-fpm.service
A note about installing phpredis on RHEL 8
The procedure and commands are the same as above. Please note that Red Hat or IBM won’t provide any support for 3rd party repos and software.
Conclusion
Redis is a popular in-memory data structure tool implementing a distributed, in-memory key-value database server. It is used to speed up dynamic web apps. To talk with the Redis server, you need phpredis exentsion on CentOS 8. However, CentOS 8/RHEL 8 ships without phpredis extension. Hence, we need to enable EPEL and Remi repos. You need working PHP 7 and Nginx server too. See the following tutorials:
- Install Nginx on CentOS 8
- Set up and configure PHP 7.x on CentOS 8 For Nginx
- Setup Let’s Encrypt on CentOS 8 for Nginx
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |