Solution 1:

You can use my ppa, that I have created for this purpose. Please take notice of the pinning that is necessary. Also, aptitude will not recognize the pinning. You must use the aptitude specific method if you want to use it.

Note - this is for 10.04 (lucid) only

Solution 2:

It is possible to use karmic packages and pin them with aptitude. This can be done by using this commands:

# 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: php5\nPin: release a=karmic\nPin-Priority: 991\n"  | sudo tee   /etc/apt/preferences.d/php > /dev/null
apt-cache search php5-|grep php5-|awk '{print "Package:", $1,"\nPin: release   a=karmic\nPin-Priority: 991\n"}'|sudo tee -a /etc/apt/preferences.d/php > /dev/null
apt-cache search -n libapache2-mod-php5 |awk '{print "Package:", $1,"\nPin: release a=karmic\nPin-Priority: 991\n"}'| sudo tee -a /etc/apt/preferences.d/php > /dev/null
echo -e "Package: php-pear\nPin: release a=karmic\nPin-Priority: 991\n"  | 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

Got this from link text

Solution 3:

There's a great blog post about this at http://civicactions.com/blog/2010/may/26/ubuntu_1004_and_drupal?page=1#comment-3717

Solution 4:

I've recently tried to solve the same problem myself. Instead of making changes to the package management I compiled PHP 5.2.17 from the source code myself and then used the program Checkinstall to install the new .deb package on my system.

I wrote up the steps in a blog post, Compiling PHP 5.2 for Ubuntu 10.10, but the steps basically involved the following:

  1. Download PHP source (http://php.net/downloads.php) to /usr/local/src
  2. Configure source, reading INSTALL doc and output from ./configure --help

my configure command looked like this:

./configure --prefix=/opt --with-apxs2=/usr/bin/apxs2 --with-curl=/usr/lib --with-pgsql --with-pear --with-mysql --with-gd
  1. Compile the source using 'make'
  2. Install the compiled package using 'checkinstall'

And that was it. I had already installed Apache2 using Synaptic (you need to use the apache2-mpm-prefork package for use with PHP). Also if you had any PHP5 pacakges already installed you would need to uninstall them before trying to install your own compiled package.

Compiling the package yourself really doesn't take long at all and is a good experience if you haven't done it already on your Ubuntu machine.