How To Install PHP 8.0 On CentOS 8 / RHEL 8

0

PHP is an open-source programming language that is embedded in HTML. It is mainly used for creating dynamic web sites such as blogs, e-commerce sites, etc. Rasmus Lerdorf created it in 1994.

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

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

Add Remi Repository

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

Remi repository requires EPEL repository be enabled on the system. So, install the latest EPEL repository auto-configuration rpm on the system to enable the EPEL repository.

dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Then, 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.4 MB/s | 5.8 MB     00:04    
CentOS-8 - Base                                                                    128 kB/s | 2.2 MB     00:17    
CentOS-8 - Extras                                                                  3.8 kB/s | 8.6 kB     00:02    
CentOS-8 - PowerTools                                                              764 kB/s | 1.9 MB     00:02    
Extra Packages for Enterprise Linux Modular 8 - x86_64                              30 kB/s |  98 kB     00:03    
Extra Packages for Enterprise Linux 8 - x86_64                                     4.6 MB/s | 8.4 MB     00:01    
Google Cloud SDK                                                                   5.4 MB/s |  22 MB     00:04    
Google Compute Engine                                                              2.1 kB/s | 6.9 kB     00:03    
remi-release-8.rpm                                                                  15 kB/s |  23 kB     00:01    
Dependencies resolved.
===================================================================================================================
 Package                      Arch                Version                          Repository                 Size
===================================================================================================================
Installing:
 remi-release                 noarch              8.1-2.el8.remi                   @commandline               23 k
Upgrading:
 centos-release               x86_64              8.2-2.2004.0.2.el8               BaseOS                     21 k
Installing dependencies:
 centos-gpg-keys              noarch              8.2-2.2004.0.2.el8               BaseOS                     12 k
 centos-repos                 x86_64              8.2-2.2004.0.2.el8               BaseOS                     13 k

Transaction Summary
===================================================================================================================
Install  3 Packages
Upgrade  1 Package

Total size: 69 k
Total download size: 46 k
Downloading Packages:
(1/3): centos-gpg-keys-8.2-2.2004.0.2.el8.noarch.rpm                                12 kB/s |  12 kB     00:01    
(2/3): centos-repos-8.2-2.2004.0.2.el8.x86_64.rpm                                   12 kB/s |  13 kB     00:01    
(3/3): centos-release-8.2-2.2004.0.2.el8.x86_64.rpm                                 20 kB/s |  21 kB     00:01    
-------------------------------------------------------------------------------------------------------------------
Total                                                                               12 kB/s |  46 kB     00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Running scriptlet: centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/1 
  Installing       : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/5 
  Upgrading        : centos-release-8.2-2.2004.0.2.el8.x86_64                                                  2/5 
  Installing       : centos-repos-8.2-2.2004.0.2.el8.x86_64                                                    3/5 
  Installing       : remi-release-8.1-2.el8.remi.noarch                                                        4/5 
  Cleanup          : centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 
  Running scriptlet: centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 
  Verifying        : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/5 
  Verifying        : centos-repos-8.2-2.2004.0.2.el8.x86_64                                                    2/5 
  Verifying        : remi-release-8.1-2.el8.remi.noarch                                                        3/5 
  Verifying        : centos-release-8.2-2.2004.0.2.el8.x86_64                                                  4/5 
  Verifying        : centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 

Upgraded:
  centos-release-8.2-2.2004.0.2.el8.x86_64                                                                         

Installed:
  remi-release-8.1-2.el8.remi.noarch                     centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                
  centos-repos-8.2-2.2004.0.2.el8.x86_64                

Complete!

Once you install the Remi repository rpm, list the available PHP module streams.

dnf module list php

You should see the below output.

CentOS-8 - AppStream
Name              Stream                Profiles                                Summary                            
php               7.2 [d]               common [d], devel, minimal              PHP scripting language             
php               7.3                   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             
php               remi-8.0              common [d], devel, minimal              PHP scripting language             

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Install PHP 8.0 on CentOS 8 / RHEL 8

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

dnf module enable php:remi-8.0 -y

Output:

Dependencies resolved.
===================================================================================================================
 Package                    Arch                      Version                     Repository                  Size
===================================================================================================================
Enabling module streams:
 php                                                  remi-8.0                                                    

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

Complete!

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

Install PHP 8.0 on CentOS 8 / RHEL 8 with the dnf command.

dnf install -y php php-cli php-common

Install PHP 7.x on CentOS 8 / RHEL 8

Enable php:remi-7.x module to install PHP 7.x on the system as shown in this article.

Install PHP-FPM

If you are setting up the 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 that enable specific support for your code.

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

dnf install -y php-mysqlnd

The below command would now list the installed MySQL extension.

php -m | grep -i mysql

Output:

mysqli
mysqlnd
pdo_mysql

Conclusion

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

You might also like