Upgrade PHP 7.0 to 7.2 on Centos

This is solution for CentOS 6.x and 7.x:

yum install epel-release

then install Remi repo, for Centos 6.x:

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-6.rpm

and for Centos 7.x:

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

check which PHP packages installed:

yum list installed php*

remove current PHP:

yum remove php*

install same packages as were installed for 7.0 using PHP 7.2, for example:

yum install --enablerepo=remi-php72 php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

check version of PHP installed:

php -v

You don't need to PHP 7.0 and 7.2 coexist on Your server. If You got a problem using PHP 7.2 You can always reinstall older PHP 7.0. If not sure it will work for You on production server, try it on virtual machine first. But it worked for me on many production servers. PHP is not critical OS component, so server will never fail if PHP changed. It's just Your web app which may fail when change to 7.2, but as I wrote it's unlikely and You may reinstall older version if it happens.

I forgot about php.ini. If You want to keep Your php.ini customizations in another PHP version, make a copy of php.ini before running yum remove php*. After PHP reinstall diff saved_php.ini php.ini and look what is need to be merged.


Yes, you can install multiple versions of PHP simultaneously, without having to build anything, only using RPM packages.

This is exactly why Software Collections were designed.

See: PHP Configuration Tips (about switching to FPM and using software collections for recent and/or multiple php versions)

For PHP 7.2 collection, also see the Configuration wizard (and choose Multiple versions)

But, indeed, solution from @NoAngel also works if you think a single version is enough, especially if you have a test environment.

Tags:

Php

Centos