×


Install PHP 8 on CentOS 7 / CentOS 8 - Step by Step Process ?

PHP is the most used scripting language for web development, both websites and web applications.

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.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related PHP queries on CentOS Linux System.

In this context, we shall look into methods to perform PHP installation.


How to Install PHP 8.0 on CentOS 7 / CentOS 8 ?

To perform this installation procedure, you can use the REMI repository.


1. Install PHP 8.0 as the Default version

In order to install and have PHP 8.0 as the default version, we run the below commands.

This means replacing base packages from the distribution with ones provided by PHP 8.0.


On CentOS 8:

$ sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
$ sudo dnf -y install yum-utils
$ sudo dnf module reset php
$ sudo dnf module install php:remi-8.0 -y
$ sudo dnf install php -y
$ sudo dnf -y install php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

On CentOS 7:

$ sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo yum -y install yum-utils
$ sudo yum-config-manager –disable ‘remi-php*’
$ sudo yum-config-manager –enable remi-php80
$ sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

In addition, if we need to install any additional PHP package, we run:

$ sudo yum install php-xxx

Similarly, to check the PHP version, we use:

$ php –version
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


2. Install PHP 8.0 alongside other PHP versions

On CentOS 8:

$ sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
$ sudo dnf -y install yum-utils
$ sudo dnf module reset php
$ sudo dnf install php80

In this stage, we need to accept installation by pressing the y key.


On CentOS 7:

$ sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo yum -y install yum-utils
$ sudo yum-config-manager –disable ‘remi-php*’
$ sudo yum-config-manager –enable remi-safe
$ sudo yum -y install php80

To install additional PHP extensions we use the command below:

$ sudo yum install php80-php-xxx

For example,

$ sudo yum install php80-php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

Then we need to agree to the installation prompt.


We use the below commands to check PHP 8 version and available extensions.

$ php80 –version
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
$ php80 –modules

To upgrade to PHP 8, as the packages have the same name as in the distribution, a simple update is enough:

$ yum update


How to resolve Common issue encountered during PHP 8.0 installation on CentOS ?

Generally, there occurs a common issue while we proceed with the upgrade.

The upgrade may fail (by design) when some installed extensions are not yet compatible with PHP 8.0.

However, if these extensions are not mandatory, we can remove them before the upgrade.


[Need help with PHP installation on any Linux Distribution? We can help you. ]


Conclusion

This article covers how to install PHP 8.0 on CentOS 8/7 and RHEL 8/7.

PHP is the most used scripting language for web development, both websites and web applications.

This guide will show you how to install PHP 8.0 on CentOS 8 | CentOS 7. 

Please note the GA release is fit for running in Production if the application already supports it.


To install any additional PHP package use command syntax:

$ sudo yum install php-xxx

To Check PHP version:

$ php --version