PHP 8.0 is a major update released by the PHP team on Nov 26, 2020. It contains a large number of new features and optimizations over previous versions. To read more about read the PHP 8 change log.

REMI and EPEL are the most popular repositories contains latest RPM packages for installation. It also contains the PHP 8 RPM packages to be install on CentOS/RHEL 8 systems.

This article will describe you to how to install PHP 8 on CentOS 8 or RHEL 8 Linux system.

Before we Begin

Login to the CentOS 8 system with sudo privileged account.

Optionally, you can upgrade the current packages on your system by executing command.

dnf upgrade  

Step 1 – Enable PHP Repository

The CentOS/RHEL default repositories don’t contain latest PHP 8 packages. In order to install PHP 8 on CentOS 8 system, enable EPEL and REMI yum repositories on your system.

Open a terminal and execute below commands to configure REMI and EPEL repositories:

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

Once you installed both the above packages, Use dnf command line tool to active php:remi-8.0 repository, which contains PHP 8 packages.

sudo dnf module enable php:remi-8.0 -y  

Verify the active repository for the php packages on your system.

sudo dnf module list php  

Make sure the remi-8.0 steam is active for the php packages. It will have [e] just after the repository name. See the below screenshot:

How to Install PHP 8 on CentOS/RHEL 8 CentOS 8 PHP php 8

Step 2 – Installing PHP 8 on CentOS

Your system is ready for the PHP 8 installation. Run the following command from terminal.

sudo dnf install php php-cli php-common  

Press ‘y’ for any confirmation prompted during installation.

Once the installation succeeded, execute the below command to view installed PHP version on your syste.

php -v  

How to Install PHP 8 on CentOS/RHEL 8 CentOS 8 PHP php 8

At this stage, you have successfully install PHP 8 on CentOS 8 and RHEL 8 systems.

Step 3 – Install Apache with PHP 8 on CentOS

This is the optional step for you, if you just need PHP CLI to running php scripts.

But in most cases, we use Apache for deploying PHP based web application. Just execute the following command to Apache web server on your system.

sudo dnf install httpd -y  

Now, verity that Apache is read to serve php files over the web. Lets create php info file on your CentOS server. The default virtulhost uses /var/www/html as document root. So create a file under this directory:

echo "" >  /var/www/html/info.php  

Next access info.php file using the server ip address as below:

How to Install PHP 8 on CentOS/RHEL 8 CentOS 8 PHP php 8

Step 4 – Installing PHP Extension

Generally the web application depends on multiple PHP extension. A PHP extension is a specially formed library for the specific tasks.

View the available PHP extensions, type:

sudo dnf search php-* 

Now, install all the required PHP extension for your application.

sudo dnf install php-gd php-mbstring php-mysqlnd 

Use -m option to view currently enabled php extensions.

php -m 
php -m | grep extension-name 

Conclusion

This tutorial helped you to install PHP 8.0 including the required extension on CentOS/RHEL 8 Linux system.