Remark: you should already have switched to PHP5.3 and heck, even 5.4…. but some old projects aren’t worth the dev time to update the code to PHP 5.3 or 5.4.
Having issues with your PHP 5.2 legacy websites after migrating them to new hardware and OS releases, which normally run on PHP5.3 or 5.4?
The best way to install PHP5.2 is by adding Karmic repositories to your apt sources. This way, you can simply install PHP 5.2 from package.
An easy way to add the sources is by running a small shell script that:
1) Creates a list of all your currently installed PHP packages.
2) Create the karmic.list files sources.list.d, holding the correct repo’s
3) Create a prefences file in /etc/apt/preferences.d, that pins your PHP version to the PHP5.2 version.
This script is copy pasted from Khalid:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#!/bin/sh # Script to install PHP 5.2 from 9.10 on 10.04/12.04 # And pin it so it does not get updated PKGS=`dpkg -l | grep php | awk '{print $2}'` apt-get remove $PKGS sed s/precise/karmic/g /etc/apt/sources.list | tee /etc/apt/sources.list.d/karmic.list mkdir -p /etc/apt/preferences.d/ for PACKAGE in $PKGS do echo "Package: $PACKAGE Pin: release a=karmic Pin-Priority: 991 " | tee -a /etc/apt/preferences.d/php done apt-get update apt-get install $PKGS |
There are of course other ways of installing PHP5.2 on Ubuntu 12.04 LTS, but this one works for me… and I have had no issues so far on my servers and sites..
Credits to: Randy Fay and Khalid
UPDATE:
Due to the fact that karmic is no longer in the Archive repo’s, the script needs a little change (replace archive by old-releases)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#!/bin/sh # Script to install PHP 5.2 from 9.10 on 10.04/12.04 # And pin it so it does not get updated PKGS=`dpkg -l | grep php | awk '{print $2}'` apt-get remove $PKGS sed s/precise/karmic/g /etc/apt/sources.list | tee /etc/apt/sources.list.d/karmic.list sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list.d/karmic.list mkdir -p /etc/apt/preferences.d/ for PACKAGE in $PKGS do echo "Package: $PACKAGE Pin: release a=karmic Pin-Priority: 991 " | tee -a /etc/apt/preferences.d/php done apt-get update apt-get install $PKGS |
UPDATE2:
Today we had a crashed server that needed to be reinstalled. We had some problem with the PIN priority, packages installed still were 5.3.10… Bugger.
But looking a little further, you can use apt-mark hold to ‘pin’ package version to the installed packages.
So we had to install the PHP5.2 packages and ‘hold’ them to that version using:
1 2 3 |
apt-get install libapache2-mod-php5=5.2.10.dfsg.1-2ubuntu6.10 php-pear=5.2.10.dfsg.1-2ubuntu6.10 php5-cgi=5.2.10.dfsg.1-2ubuntu6.10 php5-cli=5.2.10.dfsg.1-2ubuntu6.10 php5-common=5.2.10.dfsg.1-2ubuntu6.10 php5-curl=5.2.10.dfsg.1-2ubuntu6.10 php5-dev=5.2.10.dfsg.1-2ubuntu6.10 php5-gd=5.2.10.dfsg.1-2ubuntu6.10 php5-imagick=5.2.10.dfsg.1-2ubuntu6.10 php5-mcrypt=5.2.10.dfsg.1-2ubuntu6.10 php5-mysql=5.2.10.dfsg.1-2ubuntu6.10 php5-xmlrpc=5.2.10.dfsg.1-2ubuntu6.10 apt-mark hold libapache2-mod-php5 php-pear php5-cgi php5-cli php5-common php5-curl php5-dev php5-fpm php5-gd php5-mysql php5-xmlrpc |