Installing Different Versions of php Using yum on Linux (CentOS 6)

I will be installing the yum default version of php.

Check You Don’t Have php Installed

[ahmed@amayem ~]$ rpm -q php
package php is not installed

Or

[ahmed@amayem ~]$ yum list installed | grep php
[ahmed@amayem ~]$

We don’t have php installed let’s check what is available:

Checking Available php Packages in Default yum Repositories

[ahmed@amayem ~]$ yum list php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.lga7.us.voxel.net
 * epel: mirror.cogentco.com
 * extras: mirror.solarvps.com
 * rpmforge: repoforge.mirror.constant.com
 * updates: mirror.us.leaseweb.net
Available Packages
php.x86_64         5.3.3-27.el6_5.1       updates

It looks like the available version is 5.3.3. Let’s see some more info:

[ahmed@amayem ~]$ yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.lga7.us.voxel.net
 * epel: mirror.cogentco.com
 * extras: mirror.solarvps.com
 * rpmforge: repoforge.mirror.constant.com
 * updates: mirror.us.leaseweb.net
Available Packages
Name        : php
Arch        : x86_64
Version     : 5.3.3
Release     : 27.el6_5.1
Size        : 1.1 M
Repo        : updates
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated webpages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            : 
            : The php package contains the module which adds support for the PHP
            : language to Apache HTTP Server. 

Based on the description it looks like this is the package that we want. Make sure you check that x86_64 is compatible with your OS. If you want a newer version then we will have to use a different yum repository. If you are happy with the version then move on to installing php.

Obtaining Newer Versions of php Using Webtatic yum Repositories

If you want a newer version of php, we will have to use a different repository such as the webtatic repositories.

Installing the webtatic-release RPM

Check here to choose your OS. I am using CentOS 6 so I will do the following:

[ahmed@amayem ~]$ sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
Retrieving http://mirror.webtatic.com/yum/el6/latest.rpm
warning: /var/tmp/rpm-tmp.GVmxOw: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
Preparing...                ########################################### [100%]
   1:webtatic-release       ########################################### [100%]

Checking the Info and Version of the Package we Want

It’s a good idea to check the package before installing it. I will check the info of php 5.5

[ahmed@amayem ~]$ yum info php55w
Loaded plugins: fastestmirror, replace
Loading mirror speeds from cached hostfile
 * base: mirrors.tummy.com
 * epel: mirror.us.leaseweb.net
 * extras: mirror.metrocast.net
 * rpmforge: repoforge.mirror.constant.com
 * updates: mirror.us.leaseweb.net
 * webtatic: us-east.repo.webtatic.com
Available Packages
Name        : php55w
Arch        : x86_64
Version     : 5.5.15
Release     : 1.w6
Size        : 2.5 M
Repo        : webtatic
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            : 
            : The php55w package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.

Looks good. The other versions will be named as follows:

  1. 5.4 -> php54w
  2. 5.5 -> php55w
  3. 5.6 -> php56w (currently in webtatic-testing repo so to see it do the following: yum info --enablerepo=webtatic-testing php56w)

Installing php

After choosing your version, it’s time to install. I will be installing the regular repo’s version 5.3, so it’s name is just php. If you want other versions check above for the name and just replace php with that name.

[ahmed@amayem ~]$ yum install php
Loaded plugins: fastestmirror
You need to be root to perform this command.

We need to be root. Check here to see how to give a linux user sudo powers.

[ahmed@amayem ~]$ sudo yum install php

There should be a lot of output with a prompt like the following:

Total download size: 3.8 M
Installed size: 13 M
Is this ok [y/N]:

Accept by entering y. More output will be displayed ending with the following:

Complete!

Congratulations it is installed now.

Restarting Apache

Make a phpinfo file as outlined here to test the newly installed php. yum should have taken care of the configuration. For the configuration to take effect we need to restart apache:

[ahmed@amayem lib]$ sudo apachectl restart

Now try opening the php page. If it still doesn’t work then try rebooting the server:

[ahmed@amayem lib]$ sudo reboot

Now it should start working.

References

  1. Webtatic repositories

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.