April 19, 2010

Installing PHP 5.2.x on CentOS

At the time of writing, PHP 5.1.6 is the “current” version shipped with CentOS 5.4. While I’m sure there is valid (?) reason for CentOS still distributing 5.1, many web developers need 5.2 functionality in their applications to run correctly.

There are two common ways to upgrade CentOs 5.4 to PHP 5.2:

  1. Download, compile and install Apache and PHP from source.
  2. Use yum with the CentOS Testing Repository

Compiling From Source

If you want to install from source, the standard ./configure; make; make install process will work in most cases (actually, if you want to do anything productive, it will be a bit more complicated than this).

While this process affords you the ability to fine-tune your configuration, you loose automatic updates and any future modifications to the Apache or PHP configuration will most likely require recompilation.

Using yum

Since we’re using CentOS, the best approach is to just go with the native package manager. Like it or not, RPM is a solid package manager which really makes life easy if used correctly. Yum is the fronted for RPM management in CentOS.

In order for yum to have access to the updated packages, you have to enable the CentOS Testing repository.

Simply create the repository in /etc/yum.repos.d

# nano -w /etc/yum.repos.d/centos-test.repo

And add the following configuration:

[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/5/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

Once completed you can upgrade PHP to the 5.2.x release:

# yum update php