How to use PHP 5.2 with Debian Squeeze

Googling in the subject shows that you can downgrade PHP packages to Lenny versions without much trouble. However the already documented methods lacked a few things I consider important, thus I write down my own downgrade instructions for future reference.

Let's assume that you already have Squeeze up and running (either a clean install or you've upgraded from Lenny).
First of all make a backup of at least your /etc directory and your package selections:
cd ~
cp -a /etc etc_$(date +%Y%m%d)
dpkg --get-selections '*' > dpkg_selections_$(date +%Y%m%d)
This always comes handy in case you mess things up.

Create an APT sources file for the lenny distribution eg. in a file named /etc/apt/sources.list.d/lenny.list with the following (or similiar) contents:
deb http://ftp.us.debian.org/debian/ lenny main contrib non-free
deb-src http://ftp.us.debian.org/debian/ lenny main contrib non-free

deb http://security.debian.org/ lenny/updates main contrib non-free
deb-src http://security.debian.org/ lenny/updates main contrib non-free

# deb http://ftp.us.debian.org/debian/ lenny-proposed-updates main contrib non-free
# deb-src http://ftp.us.debian.org/debian/ lenny-proposed-updates main contrib non-free

deb http://volatile.debian.org/debian-volatile/ lenny/volatile main contrib non-free
deb-src http://volatile.debian.org/debian-volatile/ lenny/volatile main contrib non-free

# deb http://www.backports.org/debian/ lenny-backports main contrib non-free
# deb-src http://www.backports.org/debian/ lenny-backports main contrib non-free
Note: I've included the proposed updates and backports sources too in case one might need them.

Now set up APT pinning by creating an APT preferences file: either create or edit /etc/apt/preferences or create a new one at /etc/apt/preferences.d/lenny (note that the latter filename has no extension!).
The contents should look something like this:
Explanation: by default install a package from Lenny if it is not yet installed and is not available from Squeeze
Package: *
Pin: release n=lenny*
Pin-Priority: 100

Explanation: install these packages always from Lenny
Package: libapache2-mod-php5 php5-common php5-curl php5-gd php5-mcrypt php5-mysql
Pin: release n=lenny*
Pin-Priority: 999

In the second paragraph list all packages you want to get from Lenny. This will make sure that these come always from Lenny (except if you put here a package that is not in Lenny, but let's assume you won't Smiling ). The first paragraph makes sure that Lenny-specific (ie. available only from Lenny) dependencies of packages in the second paragraph are automatically installed as well.

(As a sidenote: you can put either an asterisk ("*") or a space separated package list in the Package: line of the preferences file. It does not accept wildcards in a package name, ie. php5* will not match any package. Sad )

Update your APT caches:
apt-get update
apt-get clean

To get a full list of PHP related packages (for the following commands), go through the output of this:
dpkg --get-selections | grep php

Now purge (deinstall both packages and their config) the Squeeze PHP packages:
apt-get purge libapache2-mod-php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-suhosin

If there were any PHP related files/directories not removed during the purge, take a look at them and remove them manually if necessary. Note that probably you should not keep any PHP related stuff, since there's quite some difference between PHP 5.3 and PHP 5.2, and this is true for everything (libs, config, executables, etc.).

After the cleanup (re)install the packages, but first check if your APT configuration is OK.
For this, run apt-get in download only mode:
apt-get -d install libapache2-mod-php5 php5-curl php5-gd php5-mcrypt php5-mysql
This will print the URL for every package and you can check what package comes from what location.

(Note: if you're familiar with apt-cache you can verify the repository priorities with apt-cache policy and the package policies with apt-cache policy packagename.)

If every package comes from the right repository (the one you intend it to come from Smiling ), install the packages:
apt-get install libapache2-mod-php5 php5-curl php5-gd php5-mcrypt php5-mysql

The last step is to go through the PHP config files and apply your customizations (if you've any). Since you've a backup of your old PHP config files (your /etc directory), this should be not too difficult. And of course: don't forget to (re)start you Apache.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Great tutorial

You saved my day!

MySQL

Thanks for writing this! One thing concerns me though:

php5-mysql includes libraries for mysql 5.0 but mysql-server on squeeze is 5.1. As there are no dependencies between them they do install fine.

But are you sure that this will work? At least phpmyadmin is complaining:

Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.49. This may cause unpredictable behavior.

Guido

Re: MySQL

I had no problems since I did this Squeeze upgrade/install (tried both the upgrade from Lenny to Squeeze and installation of a new Squeeze system + keeping the old PHP 5.2 from Lenny). I admit that there's a chance of incompatibility here. If you're worried about it you can decide to keep the MySQL server from Lenny too.

TY bro!!! xD

thanks a lot bro! xD

Syndicate content