Chris Wiegman Chris Wiegman

PHP 5.2 on Ubuntu 10.04

PHP Logo

Ubuntu Server has been a great product, but even great products have their shortcomings. One of these popped up recently with the latest upgrade from Ubuntu server 9.10 to 10.04 and came in the form of a new PHP stack. For many, the migration to PHP 5.3 hasn’t been a problem. For me as a Drupal user, more specifically a user of a number of Drupal modules, that wasn’t the case. There is a solution however. Downgrade the packaged PHP 5.3 from Ubuntu 10.04 back to the PHP 5.2 packaged in Ubuntu 9.10.

Here’s how I did it:

  1. Remove PHP 5.3sudo aptitude purge `dpkg -l | grep php| awk ‘{print $2}’ |tr “n” ” “`
  2. Create a directory in /etc/apt call sources.list.d (I do believe it may be there on some installs, but I wasn’t so lucky)
    cd /etc/apt
  3. In /etc/apt/sources.list.d create a file called karmic.list.
    sudo mkdir sources.list.d
  4. Create the karmic.list file and add the appropriate entries.
    sudo sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
  5. Next, create the folder /etc/apt/preferences.d
    cd /etc/apt
    sudo mkdir preferences.d
  6. In preferences.d create the file php and add the following: (note I’ve just included the file to download)
    1. Download PHP
  7. Install PHP 5.2
    sudo apt-get clean
    sudo apt-get update
    sudo apt-get install libapache2-mod-php5
  8. Install any additional php packages you might need (php5-cli, gd, etc)

I’ve compiled this method from a couple of sources and successfully implemented it on our servers. If you’re running a number of php packages I would recommend running sudo dpkg -l | grep php| awk ‘{print $2}’ first to build a list of the extra packages you’ll need.