How to Install PHP 8 on CentOS 8 Linux system

By admin 172 comments 2.1k Views
3 Min Read

How to Install PHP 8 on CentOS 8 Linux system

PHP is the most popular server scripting language used for creating dynamic and interactive Web pages. Recently PHP 8 has been released officially. This tutorial explains how to install PHP 8 on CentOS 8 system.

PHP 8.0 is the latest major release and includes performance improvements, and lots of new features such as named arguments, JIT compiler, union types, match expression, and more. We’ll use the REMI repository to install PHP 8.


You must log in with root or user with Sudo privileges.

Install PHP 8 on CentOS 8

Perform the following steps to install PHP 8 on CentOS system.

Step 1 – Update System

Use the following command to update your CentOS 8 / RHEL 8 system.

sudo dnf update
sudo dnf upgrade

Once the updates applied, you can reboot your system using the below command. It’s optional to reboot.

sudo reboot

Step 2 – Enable EPEL & Remi Repository

By default, CentOS 8 package repositories don’t include PHP 8. So, we have to enable EPEL and Remi repositories. Run following commands to enable:

sudo dnf install -y epel-release
sudo dnf install -y
sudo dnf install -y dnf-utils

Step 3 – Install PHP 8

Run the following commands to reset the PHP module and install PHP 8 from remi-8.0 module.

sudo dnf module reset php
sudo dnf module install -y php:remi-8.0

Step 4 – Verify Installation

You can verify the installation using --version command:

php -v
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

By default, Nginx doesn’t have built-in support for processing PHP files. So we need to use the PHP FPM service to handle the PHP files.

sudo dnf install -y php-fpm

You must start and enable its services once the php-fpm package is installed. Run following command:

sudo systemctl enable php-fpm --now

To verify the status of php-fpm service, run:

systemctl status php-fpm

Installing PHP Extensions

You can install PHP extensions as per requirements. You can easily install extensions using the DNF package manager in the following form:

sudo dnf install -y php-[extension]

For example, to install curl and mbstring extensions, you would run the following command:

sudo dnf install -y php-{curl,mbstring}

You must restart the Apache or PHP FPM service after installing extensions.


I hope you successfully learned how to install PHP 8 on CentOS 8 / RHEL 8 system.
If you have any questions or feedback, please leave a comment below.

TAGGED: , , ,
Share This Article