I performed an upgrade on my work laptop, and upgraded from Ubuntu 9.10 to 10.04. With it came some welcome upgrades, such as Netbeans 6.8 (which is a super awesome IDE, I might add), and a slicker interface, as well as some not-so-welcome upgrades, such as PHP 5.3. Now, PHP 5.3 generates a huge number of E_DEPRECATED errors on older code, due to the fact that a lot of coding practices previously employed are now deprecated (well, especially in the CakePHP 1.2.x source).

Today, I couldn’t stand the errors anymore, and I decided to downgrade my version of PHP. This is a brief guide on how to do this.

In all fairness, it wasn’t actually Ubuntu that performed these upgrades willy-nilly. It was more my hot-headedness and thirst for the latest software that caused me to end up with latest version of PHP inadvertently installed. Also, the deprecated errors really annoy as I have XDebug installed, with HTML errors being on. So for every deprecated error, there is a mile-long output of error reporting.

Anyways, when dealing with reverting the PHP 5.3 installation, everything needs to be run through the command line (and is done assuming you have root access on the command line):

# remove all php packge
sudo aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "n" " "`

# use karmiс for php pakage
# pin-params:  a (archive), c (components), v (version), o (origin) and l (label).
echo -e "Package: php5nPin: release a=karmicnPin-Priority: 991n"  | sudo tee /etc/apt/preferences.d/php > /dev/null
apt-cache search php5-|grep php5-|awk '{print "Package:", $1,"nPin: release a=karmicnPin-Priority: 991n"}'|sudo tee -a /etc/apt/preferences.d/php > /dev/null
apt-cache search -n libapache2-mod-php5 |awk '{print "Package:", $1,"nPin: release a=karmicnPin-Priority: 991n"}'| sudo tee -a /etc/apt/preferences.d/php > /dev/null
echo -e "Package: php-pearnPin: release a=karmicnPin-Priority: 991n"  | sudo tee -a /etc/apt/preferences.d/php > /dev/null

# add karmic to source list
grep 'main restricted' /etc/apt/sources.list|grep -v "#"| sed s/lucid/karmic/g | sudo tee /etc/apt/sources.list.d/karmic.list > /dev/null

# update package database (use apt-get if aptitude crash)
sudo apt-get update

# install php
sudo aptitude install -t karmic php5-cli php5-cgi

# or (and) sudo apt-get install -t karmic  libapache2-mod-php5
sudo aptitude hold `dpkg -l | grep php5| awk '{print $2}' |tr "n" " "`

#done

This is the process I followed in order to downgrade my version of PHP. There were one or two other packages that I found weren’t re-installed, such as MySQL, cURL, and the GD library. However, these were easily installed using

sudo apt-get install php5-curl php5-mysql php5-gd php5-xdebug

I can’t take credit for this either, unfortunately – I cam across this on http://mrkandy.wordpress.com/2010/04/16/install-php-5-2-x-in-ubuntu-10-04-lucid/ earlier today.