Upgrade PHP on CentOS 6.x

This past week I was in need of a PHP upgrade on a CentOS development box. I thought the process would be trivial, but I was surprisingly mistaken. The upgrade process wasn’t a nightmare, but, as you will see, it wasn’t as easy as a yum update. I find myself performing tasks such as this quite often, and I inevitably find myself having to perform the same task sometime later, so why not make a post and refer back to it when needed 👍. This post provides a general recipe to upgrade PHP on a CentOS 6.x system.


1. Remove the old packages

First, detect if any PHP packages are installed:

$ yum list installed | grep php

You should get a list of packages including those shown below:

php.i686 5.3.3-27.el6_5 @updates php-cli.i686 5.3.3-27.el6_5 @updates php-common.i686 5.3.3-27.el6_5 @updates php-ldap.i686 5.3.3-27.el6_5 @updates php-mbstring.i686 5.3.3-27.el6_5 @updates php-pdo.i686 5.3.3-27.el6_5 @updates php-pgsql.i686 5.3.3-27.el6_5 @updates php-soap.i686 5.3.3-27.el6_5 @updates php-tidy.i686 5.3.3-27.el6_5 @updates php-xml.i686 5.3.3-27.el6_5 @updates

If packages are installed remove them, for example:

$ sudo yum remove php.i686 php-cli.i686 php-common.i686 php-ldap.i686 php-mbstring.i686 php-pdo.i686 php-pgsql.i686 php-soap.i686 php-tidy.i686 php-xml.i686

2. Add the new packages

Add the newer PHP 5.4/5.5 packages to yum using this command for CentOS 6.x

$ sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

Now you can check if the new PHP (5.4: php54w or 5.5: php55w) packages are available:

$ yum list available | grep php

Or, version specific search:
$ yum list available | grep php54

3. Install the new packages

Next, install the new PHP 5.4 or 5.5 packages, for example when installing PHP 5.5 packages:

$ sudo yum install php55w.i386 php55w-cli.i386 php55w-common.i386 php55w-ldap.i386 php55w-mbstring.i386 php55w-pdo.i386 php55w-pgsql.i386 php55w-soap.i386 php55w-tidy.i386 php55w-xml.i386

PHP should now be upgraded to the new version, you can verify with the command:

$ php -v
PHP 5.5.12 (cli) (built: May 1 2014 19:51:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

4. Restart the web server

Now you can restart the web server so the changes take place

$ sudo service httpd restart


I hope this helps any future users who have to make the upgrade 👍


Leave a Reply

Your email address will not be published. Required fields are marked *