How To Install PHP 7.4 / 7.3 On CentOS 8 / RHEL 8

0

ADVERTISEMENT

PHP is an open-source programming language widely for web development, created by Rasmus Lerdorf. It is an HTML-embedded scripting language for creating dynamic web sites.

CentOS 8 / RHEL 8 comes with PHP v7.2 by default.

In this post, we will see how to install PHP 7.4 / 7.3 on CentOS 8 / RHEL 8.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Add Remi Repository

Remi, a third-party repository which offers multiple versions of PHP (7.4 / 7.3 / 7.2) for Red Hat Enterprise Linux.

Remi repository requires EPEL repository be enabled on your system.

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

To enable the Remi repository on your system, install the Remi repository auto-configuration package using the below command.

dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Output:

CentOS-8 - AppStream                                                               1.7 MB/s | 6.3 MB     00:03    
CentOS-8 - Base                                                                    3.0 MB/s | 7.9 MB     00:02    
CentOS-8 - Extras                                                                  5.5 kB/s | 2.1 kB     00:00    
CentOS-8 - PowerTools                                                              916 kB/s | 1.8 MB     00:02    
Extra Packages for Enterprise Linux 8 - x86_64                                     1.9 MB/s | 5.2 MB     00:02    
Google Cloud SDK                                                                   6.6 MB/s |  29 MB     00:04    
Google Compute Engine                                                              1.7 kB/s | 5.8 kB     00:03    
remi-release-8.rpm                                                                  13 kB/s |  20 kB     00:01    
Dependencies resolved.
===================================================================================================================
 Package                     Arch                  Version                       Repository                   Size
===================================================================================================================
Installing:
 remi-release                noarch                8.0-4.el8.remi                @commandline                 20 k

Transaction Summary
===================================================================================================================
Install  1 Package

Total size: 20 k
Installed size: 14 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Installing       : remi-release-8.0-4.el8.remi.noarch                                                        1/1 
  Verifying        : remi-release-8.0-4.el8.remi.noarch                                                        1/1 

Installed:
  remi-release-8.0-4.el8.remi.noarch                                                                               

Complete!

List the available PHP module stream.

dnf module list php

You should see below output.

CentOS-8 - AppStream
Name              Stream                Profiles                                Summary                            
php               7.2 [d]               common [d], 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

Install PHP 7.4 on CentOS 8 / RHEL 8

Enable php:remi-7.4 module to install PHP 7.4.

dnf module enable php:remi-7.4 -y

Output

Last metadata expiration check: 0:03:03 ago on Sat 11 Jan 2020 02:41:27 PM UTC.
Dependencies resolved.
===================================================================================================================
 Package                    Arch                      Version                     Repository                  Size
===================================================================================================================
Enabling module streams:
 httpd                                                2.4                                                         
 php                                                  remi-7.4                                                    

Transaction Summary
===================================================================================================================

Complete!

Switching module streams does not alter installed packages (see 'module enable' in dnf(8) for details)

Install PHP 7.4 on CentOS 8 / RHEL 8 with dnf command.

dnf install -y php php-cli php-common

Install PHP 7.3 on CentOS 8 / RHEL 8

Enable php:remi-7.3 module to install PHP 7.3.

dnf module enable php:remi-7.3 -y

Output:

Last metadata expiration check: 0:03:03 ago on Sat 11 Jan 2020 02:41:27 PM UTC.
Dependencies resolved.
===================================================================================================================
 Package                    Arch                      Version                     Repository                  Size
===================================================================================================================
Enabling module streams:
 httpd                                                2.4                                                         
 nginx                                                1.14                                                        
 php                                                  remi-7.3                                                    

Transaction Summary
===================================================================================================================

Complete!

Switching module streams does not alter installed packages (see 'module enable' in dnf(8) for details)

Install PHP 7.3 on CentOS 8 / RHEL 8 with dnf command.

ADVERTISEMENT

dnf install -y php php-cli php-common

Check PHP Version

Once you have installed PHP, check the PHP version with the following command.

php -v

Output:

PHP 7.4.1 (cli) (built: Dec 17 2019 16:35:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies

Install PHP-FPM

If you are setting up LEMP stack on RHEL 8, you might want to install php-fpm.

dnf install -y php-fpm

Install PHP Extensions

PHP extensions are compiled libraries which enables specific support for your code.

To have MySQL support on your code, you can install php-mysqlnd package.

dnf install -y php-mysqlnd

Once you have installed MySQL extension, you can use the below command to verify it.

php -m | grep -i mysql

Output:

mysqli
mysqlnd
pdo_mysql

PHP Extensions for WordPress

The following extensions are required to install and run WordPress on your RHEL 8 machine. WordPress recommends PHP v7.3 for the installation.

dnf install -y php-dom php-simplexml php-ssh2 php-xml php-xmlreader php-curl php-date php-exif php-filter php-ftp php-gd php-hash php-iconv php-json php-libxml php-pecl-imagick php-mbstring php-mysqlnd php-openssl php-pcre php-posix php-sockets php-spl php-tokenizer php-zlib

PHP Extensions for Joomla

The following extensions are required to install and run Joomla on your RHEL 8 machine. Joomla requires PHP v7.1 and above.

dnf install -y php-mysqlnd php-zlib php-xml php-pear php-json php-mcrypt php-pecl-imagick

PHP Extensions for Drupal

The following extensions are required to install and run Joomla on your RHEL 8 machine. Drupal requires PHP v7.1 and above.

dnf install -y php-mysqlnd php-date php-dom php-filter php-gd php-hash php-json php-pcre php-pdo php-session php-simplexml php-spl php-tokenizer php-xml

Conclusion

That’s All. I hope you have learned how to install PHP 7.4 / 7.3 on CentOS 8 / RHEL 8. Please share your feedback in the comments section.

You might also like