I am a danish programmer living in Bangkok.
Read more about me @ rasmus.rummel.dk.
Webmodelling Home > Ubuntu Bits > Downgrade PHP

Downgrade PHP

20 Feb 2012 Step-by-step how to downgrade your PHP version so older legacy PHP websites can run - typically you need to downgrade to PHP 5.2.x (eg. older Mambo sites cannot run on PHP 5.3.x but can run on PHP 5.2.x).

Note that we don't downgrade to a specific PHP version, instead we downgrad PHP packages
to a specific Ubuntu release, eg. Lucid or Karmic.

Downgrade PHP using either a script or do it manually :

Appendixes :

Using a script to Downgrade PHP

After the third time I had to downgrade PHP, I decided enough is enough, documented the procedure
and made a shell script that can do it.

Download the script.

  • Script name : downgradephp.sh
  • Script version : 1.0
  • Environment : Ubuntu bash shell
  • Function : downgrades php
  • Notes : version 1.0 only works if your sources.list uses the "us" subdomain, which it will probably not if you are outside of America.

Executing the script :

  1. Copy downgradephp.sh to some folder on your Ubuntu machine.
  2. shell> su root : switch to root if you are not already root.
  3. shell> chown root:root downgradephp.sh : change owner & group to root.
  4. shell> chmod 700 downgradephp.sh : this is to make the script executable and accessible by root only.
  5. shell> ./downgradephp.sh : execute the script. There are 4 main menu options :
    • Downgrade PHP packages - use defaults (no questions asked - all PHP packages are downgraded from oneiric to karmic).
    • Downgrade PHP packages - with options - you should choose this if your source & target releases are different from oneiric & karmic
    • Downgrade PHP packages - step-by-step.
    • Restore PHP packages - if something have gone wrong.
  6. Test that you PHP packages was correctly downgraded :
    1. shell> dpkg -l | grep php : confirm your PHP packages versions.
    2. shell> dpkg --get-selections | grep php : confirm your PHP packages status (status should be "hold" so that they cannot be updated).

Congratulations - your PHP packages should have been downgraded, you can now run your legacy PHP sites, eg. Mambo sites.

Step-by-step how to manually Downgrade PHP

I often like to do things manually the first time, however if you have many PHP packages or have to downgrade PHP on more than one server, you should go with the script solution above. Otherwise read on.

Using the tactics of downgrading PHP by Ubuntu releases, the relevant files to work with are :

  • /etc/apt/sources.list : contains references to the package archives for your current Ubuntu release.
  • /etc/apt/sources.list.d/karmic.list : we will create this file that contains references to the package archvies for the Ubuntu karmic release.
  • /etc/apt/preferences.d/php_karmic : we will create this file that contains preferences for our PHP packages.

There are 2 main package archives :

Ok, let's get to it - downgrade PHP from oneiric to karmic : (the resulting PHP version will be 5.2.10)

  1. shell> dpkg -l | grep php : display a list of all your PHP relevant packages and write them down (note that phpmyadmin is NOT a PHP package).
  2. Based on the default sources.list create a new sources list that refer to the karmic release :
    • shell> sed s/oneiric/karmic/g /etc/apt/sources.list > /etc/apt/sources.list.d/karmic.list
  3. If your target release is karmic (which indeed is here), then you need to switch the karmic sources file to use the old releases archives : (as karmic is not any longer a supported release)
    • shell> sed -i s@http://us.archive.@http://old-releases.@ /etc/apt/sources.list.d/karmic.list : note the "us" - be sure to use the correct country identifier for your system.
  4. shell> apt-get update : it is necessary to do an update after changing or adding sources.
  5. shell> nano /etc/apt/preferences.d/php_karmic : create a new preferences file called php_karmic and for each PHP package listed above add the following : (here for the php5-common package)
    • Package: php5-common
    • Pin: release a=karmic
    • Pin-Priority: 991
  6. Press ctrl+x and then y to exit nano and save the php_karmic file.
  7. shell> apt-get remove --purge php5-common : purge the php5-common package.
    • ... Continue to purge ALL PHP packages ...
  8. shell> aptitude -t karmic install php-common : install php5-common from the Karmic release.
    • ... Continue to install ALL PHP packages ...
  9. shell> dpkg --get-selections | grep php : will show the status of php related packages, eg. install, hold or deinstall - at this point all packages should have status of install and they needed to be set on hold.
  10. shell> echo "php5-common hold" | dpkg --set-selections : set php5-common package on hold to avoid it to be updated.
    • ... Continue to set ALL PHP packages on hold ...

Congratulations - your PHP packages should have been downgraded, you can now run your legacy PHP sites, eg. Mambo sites.

Appendix : Common errors & solutions

  1. shell> aptitude -t karmic install xxx errors E: The value 'karmic' is invalid for APT::Default-Release as such a release is not available in the sources

Reason : If you have the above error 1, most likely your karmic sources file is referencing the wrong archives. Note that the karmic (koala 9.10) release is NOT any longer supported and therefore not in the default archives.

Solution : Change your karmic sources file to reference the old-releases Ubuntu archives http://old-releases.ubuntu.com/ubuntu/ :

  1. shell> cd /etc/apt/sources.list.d : navigate to the karmic sources list folder (here I assume your karmic sources file is /etc/apt/sources.list.d/karmic.list).
  2. shell> sed -i s@http://us.archive.@http://old-releases.@ karmic.list : note the us part which is a country identifier subdomain, please substitute with the country identifier found in your own /etc/apt/sources.list.d/karmic.list file.
  3. shell> apt-get update : don't forget to update, otherwise the error will persist.


You can comment without logging in
 B  U  I  S 
Words: Chars: Chars left: