Upgrade PHP from 5.4 to 5.6 on CentOS 7

I recently went through the trials and tribulations of upgrading PHP on my VM running CentOS 7 so I thought I'd document how I did it.

The key to it is the Remi RPM Repository but I made the dumb mistake of adding the repos for the CentOS 6 version of the 5.6 upgrade so to fix that I removed all of the repos I just added:

rm -rf /etc/yum.repos.d/remi*

and then I just added what I needed manually:

cat > /etc/yum.repos.d/remi-php56.repo << EOF
[remi-php56]
name=remi-php56
baseurl=http://rpms.famillecollet.com/enterprise/7/php56/x86_64/
enabled=1
gpgcheck=0
EOF

Then you need to clear the cache:

yum clean expire-cache

and re-run the update

yum update

You might get some errors like so:

Error: Package: php-gd-5.6.22-1.el7.remi.x86_64 (remi-php56)
       Requires: libgd.so.3()(64bit)
Error: Package: php-gd-5.6.22-1.el7.remi.x86_64 (remi-php56)
       Requires: gd-last(x86-64) >= 2.1.1
Error: Package: php-pecl-zip-1.13.2-1.el7.remi.5.6.x86_64 (remi-php56)
       Requires: libzip.so.4()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

To fix these:

wget http://rpms.famillecollet.com/enterprise/7/remi/x86_64/gd-last-2.2.1-2.el7.remi.x86_64.rpm

yum localinstall gd-last-*.rpm

wget http://rpms.famillecollet.com/enterprise/7/remi/x86_64/libzip-last-1.1.3-1.el7.remi.x86_64.rpm

yum localinstall libzip-last-*.rpm

yum update

That should have worked, so try running php -v.

You might have some warnings like I did:

PHP Warning:  PHP Startup: newrelic: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
in Unknown on line 0
PHP Warning:  PHP Startup: ssh2: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
in Unknown on line 0
PHP 5.6.22 (cli) (built: May 26 2016 15:36:45)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

New Relic is easy to fix:

newrelic-install install

and for ssh2, I just removed it:

rm -rf /etc/php.d/ssh2.ini

re-reun php -v to confirm that the warnings are gone.

Hope it helps.