I 've a working production server that runs PHP 7.0, and I want to upgrade to 7.2.

I haven't found anything online that would suggest that PHP7.0 and 7.2 can co-exist. What would be the proper procedure? Just remove all php70w* packages and install all php72w ones?

This is a production server, errors must not cause it to fail.


  • After Upgraded PHP version how to adding PHP package to Centos - Nginx environment variable? @Michael Chourdakis
    – zus
    Commented Feb 5, 2020 at 4:34

4 Answers 4


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.

  • Can you please tell how to install PHP 7.0.2 in cent os Commented Jun 21, 2018 at 8:16
  • @DeveloperMJ 7.0.2 is a minor update of 7.0, so You may need to install 7.0, for example, using remi-php70 repository in commands above. If You absolutely unconditionally need 7.0.2, I think it's better to build it from source and install it somewhere under /usr/local. I don't know Centos repository which has exactly 7.0.2, most of them use 7.0 with latest patch, like 7.0.30. Look rpms.famillecollet.com/enterprise/7.4/php70/x86_64 they have only 7.0.29, all older files are removed.
    – NoAngel
    Commented Jun 25, 2018 at 10:12
  • Top man, nice and easy
    – Nicolas
    Commented Jun 30, 2018 at 13:13

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.

  • After Upgraded PHP version how to adding PHP package to Centos - Nginx environment variable? @Remi Collet
    – zus
    Commented Feb 5, 2020 at 4:33

Yes, you can keep multiple version at the same time. Now you have 7.0 on server so you can download source from php official website and build it to another location.

Also you can use mod_fcgid or php-fpm to execute your PHP web applications with new php version. You can refer below steps to build php from source.

  1. Download php source archive from php official mirror.
  2. Extract archive in your server and then change directory to extracted directory.
  3. Install dependencies required for build

yum install libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libicu-devel gcc-c++ libxslt-devel net-snmp-devel readline-devel aspell-devel unixODBC-devel libc-client-devel freetype-devel libvpx-devel enchant-devel libmcrypt-devel krb5-devel libtidy-devel bzip2-devel

  1. Use below commands to configure and build PHP.

./configure --prefix=/usr/local/php --enable-mbstring --with-curl --with-openssl --with-xmlrpc --enable-soap --enable-zip --with-gd --with-jpeg-dir --with-png-dir --with-mysqli --with-freetype-dir --enable-intl --with-xsl --with-mcrypt --with-zlib --enable-bcmath --enable-dba --enable-calendar --enable-exif --enable-ftp --enable-pcntl --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-opcache --with-gettext --with-bz2 --with-mhash --with-readline --with-tidy --with-libdir=lib64

note : you can change prefix if want to change installation directory.

make && make install

It will install PHP binaries and libraries to the prefix directory you mentioned in configure command.

  1. Now install mod_fcgid module in apache to use new version for php scripts executions

yum install mod_fcgid

create a file with name php-fcgi in cgi-bin directory(possible path is /var/www/cgi-bin), and add below content.

export PHPRC
exec  /usr/local/php/bin/php-cgi

Assign execute permission to the cgi file.

AddHandler php7-fastcgi .php
Action php7-fastcgi /cgi-bin/php-fcgi
Options -Indexes +FollowSymLinks +ExecCGI
DirectoryIndex index.php

<IfModule mod_fcgid.c>
         FcgidIdleTimeout 3600
         FcgidProcessLifeTime 3600
         FcgidBusyTimeout 3600
         FcgidIOTimeout 3699
         FcgidConnectTimeout 20

Now you can use this handler to any virtualhost where you want to use latest PHP version.

Before doing this on production you must have to try it on local/dev system to avoid any unexpected errors. Also ./configure --help can help you to choose php modules you currently using on production server.

  • After Upgraded PHP version how to adding PHP package to Centos - Nginx environment variable? @Vaibhav Panmand
    – zus
    Commented Feb 5, 2020 at 4:35

The Remi repo instructions are linked below. For example if you have CentOS version 7.4 then at the command line:

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
yum install yum-utils
yum-config-manager --enable remi-php72
yum update

All future updates for PHP will be for version 7.2.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .