Downgrade PHP 5.4 to PHP 5.3

So you got your fresh Debian 7 installed and realized in terror that it ships with PHP 5.4!

Most of the popular CMS out there are not ready for the changes in php core yet so you actually need to downgrade php 5.4 to php 5.3.
Here is how :

Most of the commands are self explanatory so you could just just copy & paste them into cli.

Edit the /etc/apt/sources.list file

vi /etc/apt/sources.list

and add the old Debian 6 repositories

deb http://ftp.us.debian.org/debian/ squeeze main contrib non-free
deb-src http://ftp.us.debian.org/debian/ squeeze main contrib non-free

save the file

Create the /etc/apt/preferences.d/preferences file that will allow us to “pin” the older php packages to whatever we like.
vi /etc/apt/preferences.d/preferences

and insert the packages you need to have downgraded to previous version
usually the following are enough but modify further if needed

Package: php5*
Pin: release a=oldstable
Pin-Priority: 700

Package: libapache2-mod-php5
Pin: release a=oldstable
Pin-Priority: 700

Package: libapache2-mod-php5
Pin: release a=oldstable
Pin-Priority: 700

Package: php-pear
Pin: release a=oldstable
Pin-Priority: 700

Package: *
Pin: release a=stable
Pin-Priority: 600

Now remove the pre-installed php 5.4 and all its dependencies with the following command
aptitude remove `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

Update the apt-get so we it can find the older php version
apt-get update

Tell the system to install the version we want and previously pinned in the preferences file
apt-get -t oldstable install `dpkg -l | grep php5| awk '{print $2}' |tr "\n" " "`

Confirm success with the following
dpkg -l | grep php

Restart apache
/etc/init.d/apache2 restart

And there you have it! Brand old php 5.3 in Debian 7 :
Greeeat succeeeess!

borat_great_success

Published by

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.