Upgrading PHP 7.4 to PHP 8 on CentOS 8

Spread the love

Below are the commands you should run in order to upgrade to PHP 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 
# Most probably the next step would not be needed
sudo dnf install php -y 
# and at last install extensions
sudo dnf -y install php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

You may face issue like

Error:
  Problem: cannot install both php-common-8.0.0-1.el8.remi.x86_64 and php-common-7.4.13-1.el8.remi.x86_64
 package php-pecl-mysql-1.0.0-0.23.20190415.d7643af.el8.remi.7.4.x86_64 requires php(api) = 20190902-64, but none of the providers can be installed
 package php-pecl-mysql-1.0.0-0.23.20190415.d7643af.el8.remi.7.4.x86_64 requires php(zend-abi) = 20190902-64, but none of the providers can be installed
 cannot install the best candidate for the job
 problem with installed package php-pecl-mysql-1.0.0-0.23.20190415.d7643af.el8.remi.7.4.x86_64
 package php-common-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64 is filtered out by modular filtering
 package php-common-7.4.12-1.el8.remi.x86_64 is filtered out by modular filtering
 package php-common-7.4.13-1.el8.remi.x86_64 is filtered out by modular filtering 

In that case simply remove the old extension. For example to resolve above error I had to remove mysql extension by using following command:

yum remove php-mysql

And now you can check the php version by using following command

php -v

Which would show the result

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