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

PHP is a popular open-source server-side scripting language that is integral in developing dynamic web pages. PHP 8.0 is finally out and was released on November 26th, 2020. It promises lots of improvements and optimizations which are set to streamline how developers write and interact with PHP code.

In this guide, you will learn how to install PHP 8.0 on CentOS 8/7 and RHEL 8/7.

Step 1: Enable EPEL and Remi Repository on CentOS/RHEL

Right off the bat, you need to enable the EPEL repository on your system. EPEL, short for Extra Packages for Enterprise Linux, is an effort from the Fedora team that provides a set of additional packages that are not present by default on RHEL & CentOS.

$ sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm  [On CentOS/RHEL 8]
$ sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm  [On CentOS/RHEL 7]

Remi repository is a third-party repository that provides a wide range of PHP versions for RedHat Enterprise Linux. To install the Remi repository, run the command:

$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm  [On CentOS/RHEL 8]
$ sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm  [On CentOS/RHEL 7]

Step 2: Install PHP 8 on CentOS/RHEL

Once the installation is complete, proceed and list the available php module streams as shown:

$ sudo dnf module list php   [On RHEL 8]

Right at the bottom, be sure to notice the remi-8.0 php module.

List PHP 8 Modules
List PHP 8 Modules

We need to enable this module before installing PHP 8.0. To enable php:remi-8.0, execute:

$ sudo dnf module enable php:remi-8.0 -y [On RHEL 8]
Enable PHP Remi Module
Enable PHP Remi Module

On CentOS 7, use the following commands.

$ sudo yum -y install yum-utils
$ sudo yum-config-manager --disable 'remi-php*'
$ sudo yum-config-manager --enable remi-php80

Once enabled, install PHP 8.0 for Apache or Nginx web server as shown:

Install PHP 8.0 for Apache

To install PHP 8 on the installed Apache web server, run:

$ sudo dnf install php php-cli php-common
Install PHP 8 for Apache
Install PHP 8 for Apache

Install PHP 8.0 for Nginx

If you are using Nginx in your development stack, consider installing php-fpm as shown.

$ sudo dnf install php php-cli php-common php-fpm

Step 3: Verify PHP 8.0 on CentOS/RHEL

There are two ways that you can use to verify the PHP version. On command-line, issue the command.

$ php -v
Verify PHP 8 from Command-line
Verify PHP 8 from Command-line

Additionally, you can create a sample php file in the /var/www/html folder as shown:

$ sudo vim /var/www/html/info.php

Then add the following PHP code which will populate the version of PHP alongside installed modules.

<?php

phpinfo();

?>

Save and exit. Be sure to restart the Apache or Nginx web server as shown.

$ sudo systemctl restart httpd
$ sudo systemctl restart nginx

Next, head over to your browser and go to the address shown:

http://server-ip/info.php

The webpage displays a wealth of information regarding the version of PHP installed such as build date, build system, Architecture, and a host of PHP extensions.

Check PHP 8 Info
Check PHP 8 Info

Step 3: Install PHP 8.0 Extensions in CentOS/RHEL

PHP extensions are libraries that provide added functionality to PHP. To install a php extension, use the syntax:

$ sudo yum install php-{extension-name}

For example, to enable PHP to seamlessly work with MySQL, you can install the MySQL extension as shown.

$ sudo yum install php-mysqlnd

Finally, you can verify the installed extensions using the command:

$ php -m

To verify if a specific extension is installed, execute:

$ php -m | grep extension-name

For example:

$ php -m | grep mysqlnd
Verify PHP Extension
Verify PHP Extension

In the end, we hope that you can now comfortably install PHP 8.0 alongside various php extensions on CentOS/RHEL 8/7.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

14 thoughts on “How to Install PHP 8 on CentOS/RHEL 8/7”

  1. Sometimes it is necessary to reset the php module:

    # dnf module enable php:remi-8.1
    

    Error: It is not possible to switch enabled streams of a module unless explicitly enabled via the configuration option module_stream_switch.

    It is recommended to rather remove all installed content from the module, and reset the module using the ‘dnf module reset‘ command. After you reset the module, you can install the other stream.

    # dnf module reset php
    # dnf module enable php:remi-8.1
    
    Reply
  2. Hi,

    On my centos 7, I have enabled the php80 repo and tried to update from php74 to php80 and I’m getting the below error, please suggest this.

    Error: Package: php-pecl-interbase-1.0.0~DEV.20190523-4.el7.remi.7.4.x86_64 (@remi-php74)
    Requires: php(zend-abi) = 20190902-64
    Removing: php-common-7.4.30-1.el7.remi.x86_64 (@remi-php74)
    php(zend-abi) = 20190902-64
    Updated By: php-common-8.0.21-2.el7.remi.x86_64 (remi-php80)
    php(zend-abi) = 20200930-64
    Available: php-common-8.0.20-1.el7.remi.x86_64 (remi-php80)
    php(zend-abi) = 20200930-64
    Error: Package: php-enchant-8.0.21-2.el7.remi.x86_64 (remi-php80)
    Requires: libenchant-2.so.2()(64bit)
    Error: Package: php-pecl-interbase-1.0.0~DEV.20190523-4.el7.remi.7.4.x86_64 (@remi-php74)
    Requires: php(api) = 20190902-64
    Removing: php-common-7.4.30-1.el7.remi.x86_64 (@remi-php74)
    php(api) = 20190902-64
    Updated By: php-common-8.0.21-2.el7.remi.x86_64 (remi-php80)
    php(api) = 20200930-64
    Available: php-common-8.0.20-1.el7.remi.x86_64 (remi-php80)
    php(api) = 20200930-64
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    Reply
    • @Suresh,

      I suggest you first remove the installed PHP and its extensions and then re-install the PHP using the php80 repo…

      Reply
  3. FYI your commands only work for RHEL/CentOS 8. There is no dnf or module in yum for RHEL/CentOS 7. This is fine however your title says “How to Install PHP 8 on CentOS/RHEL 8/7” but you’re really only explaining it for 8.

    Reply
    • @Alex,

      Yes, you are correct, in that case, you need to install PHP 8 with the Yum command as shown.

      # yum install -y --enablerepo=remi-php80 php php-cli
      

      Also, I have updated the article and included instructions for CentOS 7.

      Reply
  4. That’s great. But in the past, I’ve had troubles with some of Remi’s php implementation and always preferred IUS repos versions of PHP. Is there any EL8 appstream version of PHP 8 besides Remi’s?

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.