The latest Long Term Support (LTS) release from Ubuntu has been with us for a bit over a month now, and I love it so far, on my laptop. This is Lucid Lynx 10.04, and will be supported until 2013 on the desktop, and more importantly, until 2015 on the server.
My servers are still on 8.04 though, the previous LTS, for good reason. 10.04 has PHP 5.3. While this is generally a better PHP, it has some compatibility issues with many Drupal, mainly for contributed modules, but some in core as well.
The long term solution to this is to find all PHP 5.3 compatibility issues and fix them in the code. This is a lengthy process though, and will not happen overnight.
So, in the meantime, there are several solutions for running PHP 5.2 on Lucid, some better than others.
In this post, we examine the different approaches, and the merits of each.
Approach 1: Installing Karmic's PHP 5.2 packages
The most common approach is to install Karmic 9.10's PHP 5.2 packages on 10.04. This has been reported to work for many, such as here, here and here.
The detailed instructions were originally posted here, and the following script is a refinement of that approach:
#!/bin/sh # Script to install PHP 5.2 from 9.10 on 10.04 # And pin it so it does not get updated PKGS=`dpkg -l | grep php | awk '{print $2}'` apt-get remove $PKGS sed s/lucid/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
This is not the best solution though for many reasons, the main one is that these packages were compiled against libraries built for 9.10 and not 10.04. There is always a risk of unpredictable things happening when doing such a thing.
It also requires the packages to be "pinned" so no future security updates would be provided, unless 9.10 gets them too.
I also found no easy way to pin with aptitude, rather than with apt-get.
Approach 2: Proper PHP 5.2 packages, compiled for Lucid, installed manually
The fine folk at The Jibe took this one step further and built PHP 5.2 .deb packages for Lucid.
What this approach provides is that the packages are built against Lucid headers, and therefore solves the issue mentioned above.
What this solution suffers from is the lack of a repository. This means that the packages have to be downloaded and installed manually. Also, if you install them directly via the dpkg -i command, there may be unmet dependencies if you have not installed PHP 5.3 previously. This can be overcome by running the gdebi command instead, available in the "gdebi-core" package.
Still, the previous approach is too manual, and there is no way to check automatically for security updates for example.
Approach 3: Proper PHP 5.2 packages, compiled for Lucid, installed from a repository
So, the best solution, is to install from a repository
Ralph Janke's PHP 5.2 repository for Lucid
If you have the package "python-software-properties installed, you can easily add the repository using the command:
add-apt-repository ppa:txwikinger/php5.2
That will install the GPG key for security verification.
If you are using apt-get, then you need to create a file called /etc/apt/preferences.d/php for pinning the versions, so they remain at 5.2 and don't get upgraded to 5.3 when you run apt-get to upgrade your installation.
Put this in the file:
Package: libapache2-mod-php5 Pin: version 5.2.10* Pin-Priority: 991 Package: libapache2-mod-php5filter Pin: version 5.2.10* Pin-Priority: 991 Package: php-pear Pin: version 5.2.10* Pin-Priority: 991 Package: php5 Pin: version 5.2.10* Pin-Priority: 991 Package: php5-cgi Pin: version 5.2.10* Pin-Priority: 991 Package: php5-cli Pin: version 5.2.10* Pin-Priority: 991 Package: php5-common Pin: version 5.2.10* Pin-Priority: 991 Package: php5-curl Pin: version 5.2.10* Pin-Priority: 991 Package: php5-dbg Pin: version 5.2.10* Pin-Priority: 991 Package: php5-dev Pin: version 5.2.10* Pin-Priority: 991 Package: php5-gd Pin: version 5.2.10* Pin-Priority: 991 Package: php5-gmp Pin: version 5.2.10* Pin-Priority: 991 Package: php5-ldap Pin: version 5.2.10* Pin-Priority: 991 Package: php5-mhash Pin: version 5.2.10* Pin-Priority: 991 Package: php5-mysql Pin: version 5.2.10* Pin-Priority: 991 Package: php5-odbc Pin: version 5.2.10* Pin-Priority: 991 Package: php5-pgsql Pin: version 5.2.10* Pin-Priority: 991 Package: php5-pspell Pin: version 5.2.10* Pin-Priority: 991 Package: php5-recode Pin: version 5.2.10* Pin-Priority: 991 Package: php5-snmp Pin: version 5.2.10* Pin-Priority: 991 Package: php5-sqlite Pin: version 5.2.10* Pin-Priority: 991 Package: php5-sybase Pin: version 5.2.10* Pin-Priority: 991 Package: php5-tidy Pin: version 5.2.10* Pin-Priority: 991 Package: php5-xmlrpc Pin: version 5.2.10* Pin-Priority: 991 Package: php5-xsl Pin: version 5.2.10* Pin-Priority: 991
Then you do "apt-get update" and the right packages are either pulled in due to installing them directly or indirectly through dependencies.
That works fine for apt-get.
If you are using aptitude instead of apt-get, then skip the above pinning file, and tell aptitude to hold the version of PHP to what you have installed.
aptitude hold `dpkg -l | grep php | awk '{print $2}'`
Alternatively, you can do:
for PKG in `dpkg -l | grep php | awk '{print $2}'` do echo "$PKG hold" | dpkg --set-selections done
I am not sure if the above two commands are enough to stop aptitude from upgrading the packages to 5.3 if a new release comes by. If you find a better way to let aptitude handle this, please post it below.
Resources
Some further links that you may want to check:
- Slicehost forum post on the topic of PHP 5.2 downgrade, since PHP 5.3 breaks many applications, such as Drupal, MediaWiki and others.
- Another article on Lucid 10.04 for web development. Touches on the PHP downgrade topic.
Comments
Stephan Schiegg (not verified)
The moral of the Story
Sun, 2012/01/08 - 11:32You're right. But in my case ZEND is involved too. Zend has a new Loader/Optimizer for PHP5.3, but the PHP Code i develop has to run on older PHP Versions too. I cannot maintain 2 Versions, so im stuck with PHP5.2 to be the maximum Version - unfortunately!
Visitor (not verified)
Had to use pinning
Mon, 2010/06/07 - 06:31I am happy that Ralph Janke made the effort of building a PHP 5.2 repository for Lucid, but unfortunately it's missing an APC package. Until he adds one, I go the route of pinning PHP to the Karmic packages.
Khalid
Alternate way
Mon, 2010/06/07 - 09:25No need for installing APC as a debian package.
You can always install it using pecl.
See installing APC on GNU/Linux Ubuntu and Debian. Although it says 7.10, this process works with 8.04, and should work with 10.04 as well.
Visitor (not verified)
fix
Fri, 2010/06/11 - 06:22Hi,
I corrected the script to correct some problems :
1/ pin packets not installed for futures install
2/ use the /etc/apt/preferences instead /etc/apt/preferences.d/php (bug aptitude)
3/ test the presence of the pin in the preference file
Visitor (not verified)
Hey thanks, this script fixed
Tue, 2010/08/17 - 10:53Hey thanks, this script fixed problems when I did a upgrade recently with aptitude. I also added to preferences instead of under preferences.d
Visitor (not verified)
Mcrypt issues
Fri, 2010/06/18 - 17:53For whatever reasons I had issues with mcrypt. Had to download a copy from here and install it manually http://packages.ubuntu.com/hu/karmic/i386/php5-mcrypt/download
Visitor (not verified)
Hi, Can you run me through
Mon, 2010/06/28 - 21:09Hi, Can you run me through the method of installing mcrypt for this?
Thanks!
Visitor (not verified)
mcrypt/phpmyadmin
Mon, 2010/07/12 - 08:50Thanks for really useful instructions. They pretty much worked for me.
I also had to install mcrypt manually. I followed the link above, but remember to check your architecture. I'm on amd64 so the link for me was:
http://packages.ubuntu.com/hu/karmic/amd64/php5-mcrypt/download
Download the package and then run:
sudo dpkg -i php5-mcrypt_5.2.6-0ubuntu2_amd64.deb
dpkg complained "Package libltdl7 is not installed"
so:
apt-get install libltdl7
which ran successfully, and also finished setting up php5-mcrypt.
then:
apt-get install phpmyadmin
and all is well.
Khalid
Avoid installing from .deb
Mon, 2010/07/12 - 10:35With Debian/Ubuntu, you should avoid installing from a downloaded .deb file. The reason is that you bypass the repository, which already has everything built with correct dependencies.
I will ping Ralph to add php5-mcrypt to his PPA repository, if it is missing.
If you must install something directly from a .deb file, then you should first install the gdebi-core package, and then use the command:
sudo gdebi yourpackage.deb
This will check the repository for dependencies, and install any that are required before installing your local .deb.
Visitor (not verified)
modules
Sun, 2010/07/18 - 13:59HI there,
thanks for the great PPA the downgrade is working great.
There is still the issue with mcrypt and imap which cant be installed (or updated) due to missing dependencies or installation candidates.
The following packages have unmet dependencies:
php5-imap: Depends: phpapi-20090626+lfs
E: Broken packages
E: Package php5-mcrypt has no installation candidate
also phpmyadmin cant be installed due to issue with mcrypt.
Please be so kind and notify the maker of the PPA to update it and perhaps adds all other common php5 modules
kind regards
Tibor
Pages