The content of this blog is archived. No comments may be made, and no further content will be published. Thank you for your ongoing readership! -Ryan
The best of a bad lot

« Voicemail notifications with Asterisk and Google VoiceLifehacking: the quest for efficiency »

Running PHP 5.2 on Ubuntu 10.04 LTS

Permalink 07/25/10 20:17, by Ryan, Categories: Howto , Tags: , , , , , , ,

Recently, I was tasked with installing a Drupal environment on an existing Ubuntu 10.04 LTS (lucid) server.  This release is the first Ubuntu release to ship with PHP 5.3.  Unfortunately, while the Drupal core is reasonably happy with PHP 5.3 as of late, there are likely still some modules out there that might break.

The installation for the environment in question required PHP 5.2, and I was not about to argue with it.  Fortunately, some research found a blog post with a PHP-downgrading shellscript that looked quite promising.  So, I decided to base my approach off of that.

There are alternative methods available.  A common, but misguided, approach is to uninstall the existing PHP components and compile your own PHP from source.  I am a strong believer that compiling software on a modern production server is a bad idea, for security and reliability reasons.  Another approach is to use a Personal Package Archive on Launchpad.  This is better, but I would much rather rely on the Ubuntu security team for updates than someone else (myself included!)

Since PHP 5.2 ships with karmic, lucid isn’t that much different than karmic, and karmic is still supported, why not just use the tried-and-true package management techniques?

Build a Testbed

Being a dull boy, I wanted to try this out “in the lab” before I went and blew up a client’s server.  To do this, I used a freshly-deployed VPS instance (testbox).  First, I used dpkg to clear the package selections from testbox.  Then, I cloned the selections from the production server (prodbox).  Finally, I logged into testbox and ran apt-get dselect-upgrade to apply the selections:

home$ ssh root@testbox dpkg --clear-selections
home$ ssh prodbox dpkg --get-selections | ssh root@testbox dpkg --set-selections
home$ ssh root@testbox
testbox# apt-get dselect-upgrade

Note: it goes without saying that logging in as root on a routine basis is Bad, and allowing remote ssh logins to root is also bad.  This is, however, a testbox.  I had previously used ssh-copy-id to install my public key on both testbox and prodbox.

I created the most basic of basic PHP pages, /var/www/testing.php, containing nothing more than:

<? phpinfo(); ?>

This gave me a URL to go to (http://testbox/testing.php) to make sure PHP was “there” and happy.  Once this was done, I shut down the instance and duplicated the image so I had a “known good” image.

Develop the Script

After booting, my next order of business was to look through the original script, figure out what it does, and make sure it “does the right thing."  Here, in short, is what it does:

  1. Gets the list of all installed packages with “php” in their name using dpkg -l and grep.
  2. Removes all of them – configs and all – with apt-get purge.
  3. Using apt-cache search, get a list of all php-related packages and create pins for them in /etc/apt/preferences.d/php.
  4. Add the karmic repositories to /etc/apt/sources.list.d/karmic.list, then apt-get update.
  5. Install all of the packages that were installed before using apt-get -t karmic install.
  6. Restart Apache, just because you’re probably running Apache.

I went through line-by-line, copying the “good stuff” to a shell script as I went along.  Once I was done, hoorah!  I had PHP 5.2 and all seemed well.

Test and Deploy the Script

I replaced this working image with a copy of the “known good” image, uploaded the script, and fired it.  Hoorah!  All was well.  Once that was set, I made sure a backup of prodbox was at the ready, just in case.  :-)  I then fired the script off on the real server, and… hoorah!  I checked out anything that might have broken, and indeed, all was well.

The script is available at with, of course, no guarantees of anything.  Hopefully this will be useless sooner rather than later, but we can hope!


No feedback yet

Comments are closed for this post.

Blog posts come from a can. They were put there by a man in a factory downtown.

Recent Twitterings

    Stalk me with RSS

    Search the Blog


    Support the Beer Fund

    Powered by Linode: Life's too short for crappy hosting

    [Powered by Linode]

    powered by b2evolution free blog software

    © 1962-2015 by Ryan Tucker (Public Key)

    Contact | Help | b2evolution skin by Asevo | blog software | hosts