[php] How can one run multiple versions of PHP 5.x on a development LAMP server?

I have just successfully downgraded from PHP5.3 on Ubuntu 10.

To do this I used the following script:

#! /bin/sh
php_packages=`dpkg -l | grep php | awk '{print $2}'`

sudo apt-get remove $php_packages

sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list

sudo mkdir -p /etc/apt/preferences.d/

for package in $php_packages;
do echo "Package: $package
Pin: release a=karmic
Pin-Priority: 991
" | sudo tee -a /etc/apt/preferences.d/php
done

sudo apt-get update

sudo apt-get install $php_packages

For anyone that doesn't know how to run scripts from the command line, here is a brief tutorial:

1. cd ~/
2. mkdir bin
3. sudo nano ~/bin/myscriptname.sh
4. paste in the script code I have posted above this
5. ctrl+x (this exits and prompts for you to save)
6. chmod u+x myscriptname.sh

These 6 steps create a script in a folder called "bin" in your home directory. You can then run this script by calling the following command:

~/bin/myscriptname.sh

Oulia!

Hope this helps some of you!

For reference, here is where I got the script: PHP5.2.10 for Ubuntu 10

There are several people on there all confirming that this works, and it worked a treat for me.