Uh-oh, I upgraded to Lucid Lynx but need PHP 5.2 for Drupal!

Last night I hastily decided to upgrade to Lucid Lynx on my main development machine. Generally, I try and wait a few months till things settle, but nearly 100% of the time that doesn't work. After a short battle with my wireless and some other small things, I finally settled back into "work mode" and wanted to get started working on a project I'm working on for Appalachian State University.

I quickly discovered that my local development machine had PHP 5.3 installed, doh! I went to Synaptic and thought I could do a "Package > Force Version," but alas, it's greyed out. I think this means that there's no version of PHP OLDER than 5.3 in the repos.

To accomplish what we want (getting 5.2 installed on Lucid), we need to perform a little magic with apt. Essentially, we're going to remove all the packages that are installed, configure apt to pull all of the php-related stuff from Karmic's repos, then reinstall. Here's how I did it.

This command will show you what's installed right now in terms of PHP. Run this command, and save the list somewhere (off in a text file or something).
dpkg -l | grep php

With this list in mind, you'll want to uninstall whatever's installed. My command looked like this:

$ sudo apt-get remove libapache2-mod-php5 php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-mysql

Now what we do is make a copy of the existing sources.list, and put it in as an additional repository. During the copying process, we're replacing all instances of "lucid" with "karmic" instead.

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

This essentially means that you're have both repos available to you, but by default, Ubuntu will use the later version.

Now, we're going to make a list of all the package names containing "php5" to base our preferences on.

$ apt-cache pkgnames | grep php5 > php5.list

Now, php5.list contains a list of all the php5 package names we might install. Note that in my list I have a package that does NOT contain "php5" but just "php" (for me it was "php-pear" and this caused me some problems. If there are any you see that are not php5, add their package name to this list as well by editing the file and adding each package on a new line at the end). Next, we create the preferences file, which allows us to pull from the karmic repos for anything in that list. We must transform this list a little bit, though.

The following bash script will do what you want. Copy it to a new file, and don't forget to chmod +x the file you create. (i.e. create a new text file, save as makeprefs.sh, then go out and 'chmod +x makeprefs.sh'). Then run it by using './makeprefs.sh' (no quotes of course).


#!/bin/bash
for i in `cat php5.list`; do
echo "Package: '$i'" >> php.prefs
echo "Pin: release a=karmic" >> php.prefs
echo "Pin-Priority: 991" >> php.prefs
echo >> php.prefs
done

Now move your new prefs file to the apt preferences folder:

$ sudo mv php.prefs /etc/apt/preferences.d/php

Reload the apt database so it pulls in all the karmic sources:

$ sudo apt-get update

Now, take your original apt-get 'remove' command, and switch it to "install" to re-install the 5.2 packages.

$ sudo apt-get install libapache2-mod-php5 php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-mysql

Again, those are just my packages so YMMV. Typically this will cause a reload of Apache as well, but if not you may need to restart Apache yourself.

youve got a typo in your

youve got a typo in your script that causes it not to work - putting quotes around the package name

I ran into an related glitch

I ran into an related glitch in the admin menu module. Create content, flush cache, and other items were missing from the admin menu. This post on d.o worked like a charm:
http://drupal.org/node/632142#comment-3107042

I will need to undo what I did in Admin Menu after I follow your solution?

Once you're using PHP 5.2

Once you're using PHP 5.2 there WILL be no admin_menu error, so you could undo it. However it may also still work without undoing it. :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.

More information about formatting options