How to Install PHP Extensions on CentOS 8

PHP Extensions expand the functionality of PHP.
Priyanka Sharma
Priyanka Sharma

Created: 05/26/2020 10:25 AM - Updated: 05/26/2020 10:25 AM

INTRODUCTION

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 by the use of the pecl command. 

This guide covers the installation of the PHP extension phpredis by the default CentOS 8 package manager DNF. It will also cover the installation of both PHP 7.4 and Redis on CentOS 8.

 

Prerequisites 

  • CentOS 8  server with a root user.

Step1: Install PHP 7.4

CentOS 8 provides PHP 7.2 and PHP 7.3 for installation in the default repository.Here, we will be installing PHP 7.4 as it 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.

[[email protected] ~]# 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.

[[email protected] ~]# dnf module list php

The output should look something like this.

[[email protected] ~]# 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.

[[email protected] ~]# dnf module reset php -y
[[email protected] ~]# dnf module enable php:remi-7.4 -y

4. Finally, in order to install PHP, run the command.

[[email protected] ~]# dnf install php -y

To verify that PHP 7.4 is available, check the version by running this command.

[[email protected] ~]# 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.

[[email protected] ~]# dnf install redis -y

To start and enable Redis to start on system boot, run the following command.

[[email protected] ~]# systemctl enable --now redis

Verify Redis is running by running this command.

[[email protected] ~]# systemctl enable --now redis.service
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service ? /usr/lib/systemd/system/redis.service.
[[email protected] ~]# 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[1]: Starting Redis persistent key-value database...
May 14 00:15:43 centos8.awesome.com systemd[1]: Started Redis persistent key-value database.

Step3: Install phpredis

The Remi repo set up at the beginning of this guide provides a packaged version of the phpredis extension. 

1. In order to install phpredis, run the following command.

[[email protected] ~]# dnf install -y php-pecl-redis5

Run the following command to list the currently installed PHP extensions and search for Redis among them.

[[email protected] ~]# php -m | grep redis
redis

2. Last, as a good measure, restart php-fpm.

[[email protected] ~]# systemctl restart php-fpm.service

PHP’s extensions are extremely useful in extending PHP capabilities.Installing  PHP's extensions via package managers like DNF is convenient and in most cases will minimize the amount of additional effort in getting them off and running.

Was this article helpful?

0 Out of 0 Marked As Helpfull

Have more questions? Please Contact Us