How to Install PHP Extensions on CentOS 8
This tutorial covers the installation of the PHP extension phpredis via the default CentOS 8 package manager DNF. It will also cover the installation of both PHP 7.4 and Redis on CentOS 8.
PECL, the PHP Extension Community Library, is a repository of C extensions that are loaded directly into PHP. PHP Extensions expand the functionality of PHP. PECL extensions can be installed via the use of the pecl command. There are also PHP extensions provided by package repositories. The decision of which to utilize typically depends on how PHP was installed.
- These instructions are intended specifically for installing phpredis via DNF on a CentOS 8 server.
- This tutorial was performed on a Liquid Web Self Managed CentOS 8 server as the root user.
Step #1: Install PHP 7.4
CentOS 8 provides PHP 7.2 and PHP 7.3 for installation in the default repository. PHP 7.2 is approaching EOL in 6 months and PHP 7.3 in about 18 months. Installing PHP 7.4 provides gains in the speed department and ensures a longer period of support going forward.
1. First, run the following command to set up the Remi repository, which will provide the PHP 7.4 and phpredis packages we want to install along with some handy package management utilities.
[root@centos8 ~]# dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
2. Next, take a look at the available PHP modules by running.
[root@centos8 ~]# dnf module list php
The output should look something like this.
[root@centos8 ~]# dnf module list php Extra Packages for Enterprise Linux Modular 8 - x86_64 208 kB/s | 117 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 3.8 MB/s | 6.6 MB 00:01 Remi's Modular repository for Enterprise Linux 8 - x86_64 456 kB/s | 567 kB 00:01 Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 1.1 MB/s | 1.5 MB 00:01 CentOS-8 - AppStream Name Stream Profiles Summary php 7.2 [d] common [d], devel, minimal PHP scripting language php 7.3 common, devel, minimal PHP scripting language Remi's Modular repository for Enterprise Linux 8 - x86_64 Name Stream Profiles Summary php remi-7.2 common [d], devel, minimal PHP scripting language php remi-7.3 common [d], devel, minimal PHP scripting language php remi-7.4 common [d], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
3. Next, in order to enable the PHP remi-7.4 stream run the following dnf commands.
[root@centos8 ~]# dnf module reset php -y [root@centos8 ~]# dnf module enable php:remi-7.4 -y
4. Finally, in order to install PHP, run the command.
[root@centos8 ~]# dnf install php -y
To verify that PHP 7.4 is available, check the version by running this command.
[root@centos8 ~]# php -v PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
Step #2: Install, Start, and Enable Redis
In order to make use of the phpredis extension, Redis must be installed on the system. To install Redis run.
[root@centos8 ~]# dnf install redis -y
Next, in order to start and enable Redis to start on system boot, run the following command.
[root@centos8 ~]# systemctl enable --now redis
Verify Redis is running by running this command.
[root@centos8 ~]# systemctl enable --now redis.service Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service. [root@centos8 ~]# systemctl status redis ● redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: active (running) since Thu 2020-05-14 00:15:43 EDT; 4s ago Main PID: 3606 (redis-server) Tasks: 4 (limit: 8969) Memory: 6.5M CGroup: /system.slice/redis.service └─3606 /usr/bin/redis-server 127.0.0.1:6379 May 14 00:15:43 centos8.awesome.com systemd: Starting Redis persistent key-value database... May 14 00:15:43 centos8.awesome.com systemd: Started Redis persistent key-value database.
Step #3: Install phpredis
The Remi repo set up at the beginning of this tutorial provides a packaged version of the phpredis extension. This is convenient because it eliminates some steps that would be required if it were installed with pecl.
1. In order to install phpredis, run the following command.
[root@centos8 ~]# dnf install -y php-pecl-redis5
Run the following command to list the currently installed PHP extensions and search for Redis among them.
[root@centos8 ~]# php -m | grep redis redis
2. Last, as a good measure, restart php-fpm.
[root@centos8 ~]# systemctl restart php-fpm.service
PHP's extensions are extremely useful in extending PHP capabilities. Installing them via package managers like DNF is convenient and in most cases will minimize the amount of additional effort in getting them off and running.
About the Author: Justin Palmer
Justin Palmer is a professional application developer with Liquid Web
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
How to Install React.js on WindowsRead Article
How to Use Disk Quotas in Dedicated Linux Servers with PleskRead Article
Guide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS SystemsRead Article
New User Tutorial: What is DNS?Read Article
Difference Between AlmaLinux and Rocky LinuxRead Article