Method 1 – Remi Repo
The Remi Repository (famillecollet.com) maintains the newest PHP for CentOS, RHEL, etc. And by newest, I mean newer than all other major repos.
All you need to do is install PHP with Remi enabled. As of writing this article, Remi has 5.4.23 for CentOS, RHEL, etc. If you want even newer version or any other custom version, see method #2.
yum install php
If you are also looking for how to install remi on your system, check out this guide from rackspace.
If you are using Remi, I suggest you use yum-versionlock plugin to ensure that you stay in the right version.
Method 2 – Compile your own PHP
You can download the version you want from PHP directly. As of writing the latest stable available is 5.5.7.
If you don’t already have this, you can download necessary development tools via group install.
yum groupinstall "Development Tools"
You’ll also need bunch of libraries to compile PHP. The following is a mere sample list. You may need to adjust depending on additional modules you are installing.
2 3 4 5
yum install libxml2-devel httpd-devel libXpm-devel gmp-devel libicu-devel \ t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel \ libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel \ libtidy-devel libxslt-devel
Another common library often used is mcrypt (libmcrypt-devel), but that’s available under rpmforge and not the base.
Once all the requirements are set, actual compilation is fairly simple.
Extract the php you downloaded earlier and enter directory.
tar jxf php-5.4.*.tar.bz2 cd php-5.4.23
Configure the PHP with stuff you want enabled.
./configure --enable-zip --[etc. This list can get pretty long...]
You can see a full list of PHP configuration options here.
Then finalize with build.
make make install
Now you have php 5.4.* on your Centos 6 / RHEL