How to Install PHP 7.4 on Centos 8 Linux

Table of Contents

PHP 7.4 is a significant update of the PHP language that was officially released on November 28, 2019. This is the last version in the PHP 7 series that brings in arrow functions for cleaner one-liners, preloading for improved performance, typed properties in classes, improved type variances, spread operator in arrays and much more.

In this post, we’ll download and install PHP 7.4 on Centos 8 server.

# cat /etc/centos-release
CentOS Linux release 8.5.2111

Install PHP 7.4 on Centos 8 Linux

1. First, SSH to your Centos 8 server using a root account.

2. Update CentOS 8 and install the EPEL repository using the following command:

sudo dnf -y update
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Reference:List of php 7.4 repositories for Centos, RHEL and Fedora.

3. Verify the results of installing the REMI repository, see the contents of the yum.repos.d directory.

ls -l /etc/yum.repos.d	
# ls -l /etc/yum.repos.d/
total 112
...
-rw-r--r--  1 root root  456 Sep  2 09:05 remi-php54.repo
-rw-r--r--  1 root root 1314 Sep  2 09:05 remi-php70.repo
-rw-r--r--  1 root root 1314 Sep  2 09:05 remi-php71.repo
-rw-r--r--  1 root root 1314 Oct 24 06:03 remi-php72.repo
-rw-r--r--  1 root root 1314 Sep  2 09:05 remi-php73.repo
-rw-r--r--  1 root root 1314 Oct 24 08:43 remi-php74.repo
-rw-r--r--  1 root root 1314 Sep  2 09:05 remi-php80.repo
...

4. Enable REMI PHP 7.4 repository on CentOS 8.

sudo dnf -y install dnf-utils
sudo dnf -y module reset php
sudo dnf -y module install php:remi-7.4

5. Install PHP 7.4 on CentOS 8 using the following commands:

sudo dnf -y update
sudo dnf -y install php php-cli

Install PHP 7.4 Extensions

Next, install additional packages of PHP 7.4 using the following command:

sudo dnf install php-xxx

Example, install required extensions for WordPress:

sudo dnf -y install php-fpm php-gd php-json php-mbstring php-mysqlnd php-xml php-xmlrpc

Finally, when you check the installed PHP using the command , the current PHP version should be 7.4.

# php -v
PHP 7.4.32 (cli) (built: Sep 28 2022 09:09:55) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

To view enabled modules, run the command .

# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
...
sockets
sodium
SPL
...

[Zend Modules]
Zend OPcache

To get the list of installed php extensions, run the following command:

sudo dnf list installed | grep -i php
# yum list installed | grep -i php
gd3php.x86_64                        2.3.3-7.el7.remi               @remi-safe
oniguruma5php.x86_64                 6.9.8-1.el7.remi               @remi-safe
php.x86_64                           7.4.32-1.el7.remi              @remi-php74
php-cli.x86_64                       7.4.32-1.el7.remi              @remi-php74
php-common.x86_64                    7.4.32-1.el7.remi              @remi-php74
php-fpm.x86_64                       7.4.32-1.el7.remi              @remi-php74
php-gd.x86_64                        7.4.32-1.el7.remi              @remi-php74
...

Alternatively, you can create a bash script to install PHP 7.4 on CentOS 8/RHEL 8 as follows:

#/bin/sh
###Update the CentOS 8 System
sudo dnf -y update
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

###Enable REMI PHP repository
sudo dnf -y install dnf-utils
sudo dnf -y module reset php
sudo dnf -y module install php:remi-7.4

###Install PHP 7.4 on CentOS 8/RHEL 8
sudo dnf -y update
sudo dnf -y install php php-cli
sudo yum install php-fpm php-gd php-json php-mbstring php-mysqlnd php-xml php-xmlrpc -y

Leave a Comment

Required fields are marked *