Upgrade Centos 5 tot PHP 5.2 or 5.3 [recommended way?]

Solution 1:

The excellent Remi has the very latest PHP builds for legacy distros - I upgraded Fedora 6 to PHP 5.3 recently. Once you have installed the key as above, you can install PHP 5.3.1 like so:

yum --enablerepo=remi update php-\*

This will not affect normal upgrade/installation from standard repos, as "remi" is a separate repo and not active except for during this single request.

Solution 2:

I wish I would have seen this question when it was asked. You should be very selective which 3rd party repos you install packages from. Many do not follow packaging best practices and most do not ensure non-conflicting package names. You can easily make a giant mess of your system. I gave the following answer in response to this more recent question.


I highly suggest using the IUS Community Project repositories for upgrading your PHP 5.2, and even PHP 5.3 packages on CentOS 5. These are a set of very well maintained and high quality packages, used by Rackspace and maintained, but not supported by them (unless you're a customer of course).

The install instructions can be a little hard to find if you're new to this. You're looking for the client usage guide on their wiki. I will duplicate the instructions here for ease of use.

[root@linuxbox ~]# wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm 

[root@linuxbox ~]# wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-1-1.ius.el5.noarch.rpm

[root@linuxbox ~]# rpm -Uvh ius-release*.rpm epel-release*.rpm

This downloads and installs both the EPEL and IUS repos for you.

IUS promises not to use conflicting package names with any of the official repos, including EPEL (this is a great thing), things aren't as simple as yum upgrade php. You will need to first uninstall all of your existing PHP packages, and install the appropriate ones from IUS. Alternatively, you can use the yum-plugin-replace plugin to add a useful "replace" capability to YUM.


Manually

First:

[root@linuxbox ~]# rpm -qa | grep php

[root@linuxbox ~]# yum erase php
  • rpm -qa | grep php lists each installed PHP package. You will use this list to install all the appropriate individual PHP packages from IUS
  • yum erase php command just erases PHP and it's dependent packages

Finally:

[root@linuxbox ~]# yum search php52

[root@linuxbox ~]# yum install php52 php52-common php52-pecl-apc php52-mysql ...
  • yum search php52 lists the available PHP 5.2 packages
  • yum install installs your chosen PHP 5.2 packages. You would use the list you obtained in step one to determine which you needed

yum-plugin-replace

[root@linuxbox ~]# yum install yum-plugin-replace

[root@linuxbox ~]# yum replace php --replace-with php52

This will magically determine which PHP packages to erase, and which matching php52 packages to install for you.