Drupal: How to Replace PHP 5.3 with PHP 5.2 in Ubuntu 10.4
Some modules work incorrectly with PHP 5.3. Many hosters have PHP 5.2 and you should have environment similar to server’s one for developing. Therefore it is necessary to downgrade php packet updates.
Create backup copy of php.ini file (in /etc/php5).
Create executable file:
# remove all php packge
sudo aptitude purge `dpkg -l | grep php| awk ‘{print $2}’ |tr "\n" " "`
# use karmiс for php pakage
# pin-params: a (archive), c (components), v (version), o (origin) and l (label).
echo -e "Package: php5\nPin: release a=karmic\nPin-Priority: 991\n" | sudo tee /etc/apt/preferences.d/php > /dev/null
apt-cache search php5-|grep php5-|awk ‘{print "Package:", $1,"\nPin: release a=karmic\nPin-Priority: 991\n"}’|sudo tee -a /etc/apt/preferences.d/php > /dev/null
apt-cache search -n libapache2-mod-php5 |awk ‘{print "Package:", $1,"\nPin: release a=karmic\nPin-Priority: 991\n"}’| sudo tee -a /etc/apt/preferences.d/php > /dev/null
echo -e "Package: php-pear\nPin: release a=karmic\nPin-Priority: 991\n" | sudo tee -a /etc/apt/preferences.d/php > /dev/null
# add karmic to source list
grep ‘main restricted’ /etc/apt/sources.list|grep -v "#"| sed s/lucid/karmic/g | sudo tee /etc/apt/sources.list.d/karmic.list > /dev/null
# update package database (use apt-get if aptitude crash)
sudo apt-get update
# install php
sudo aptitude install -t karmic php5-cli php5-cgi
# or (and) sudo apt-get install -t karmic libapache2-mod-php5
sudo aptitude hold `dpkg -l | grep php5| awk ‘{print $2}’ |tr "\n" " "`
#done
Execute:
php_installed=`dpkg -l | grep php| awk ‘{print $2}’ |tr "\n" " "`
This will save list of additional packets and libraries which are to be re-installed after downgrade. You can easy view them:
echo $php_installed
Run the script created earlier.
Execute:
sudo apt-get install $php_installed
This works for many packets but not for phpmyadmin which requires php5-mcrypt. They both are in "universe" repository instead of "main restricted". Threfore you should add this to /etc/apt/sources.list.d/karmic.list:
sudo gedit /etc/apt/sources.list.d/karmic.list
deb http://archive.ubuntu.com/ubuntu/ karmic universe
deb http://archive.ubuntu.com/ubuntu/ karmic-updates universe
deb http://archive.ubuntu.com/ubuntu/ karmic multiverse
deb http://archive.ubuntu.com/ubuntu/ karmic-updates multiverse
Execute:
sudo apt-get update
All packets should be updated.
You can automate this process replacing line 10 (above) with this one:
egrep ‘(main restricted|universe|multiverse)’ /etc/apt/sources.list|grep -v "#"| \
sed s/lucid/karmic/g | sudo tee /etc/apt/sources.list.d/karmic.list > /dev/null