How to install PHP 5.2 on CentOS 5
I recently needed to install PHP 5.2 on CentOS 5.3. This version of CentOS comes with PHP 5.1 but, in order to run phpMyAdmin, I needed 5.2. The CentOS software repositories are, unfortunately, still stuck with 5.1 and the only way to get a newer version of PHP installed via the package manager (yum) is to add another repository that has a newer version.
For this we will use the CentOS testing repository:
cd /etc/yum.repos.d/
sudo wget http://dev.centos.org/centos/5/CentOS-Testing.repo
sudo rpm --import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
Now we can fetch package information about PHP using the new repository:
yum --enablerepo=c5-testing info php
Check the version number. If it is what you need you can go ahead and install it using yum:
sudo yum --enablerepo=c5-testing update php
Assuming that worked, you can now restart Apache and be on your way:
sudo /etc/init.d/httpd restart
Memcache
If, like me, you were using memcache you might run into a problem where memcache never got updated to the proper version because it did not exist in the CentOS testing repository. The memcache module on the system ends up with a different PHP API version than is required by the new version of PHP you just installed.
Upon starting PHP you might see a warning similar to this:
Module compiled with API 20040429
PHP compiled with API 20060613
Again, we will add a new repository from Remi Collet. The steps should be as follows:
cd /etc/yum.repos.d/
wget http://rpms.famillecollet.com/remi-enterprise.repo
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
Now we can install the newest memcache library:
sudo yum --enablerepo=remi install libmemcached\*
Build the PHP module using Pecl (you might have to install php-devel packages for this):
pecl install memcache
Edit /etc/php.d/memcache.ini and add:
extension=memcache.so
Restart Apache:
sudo /etc/init.d/httpd restart
With a little bit of luck you will now have PHP 5.2.x and Memcache!