Downgrade PHP on Ubuntu
You just upgraded or installed the latest version of Ubuntu (10.04 or 10.10) on your PC, but it comes with PHP 5.3 and for Drupal development this is not optimal. Why is this not optimal, because not all contrib modules are compatible with PHP 5.3. More information can be found on the Drupal website (PHP section).
So you want to downgrade back to PHP 5.2 and lock it so you don't have to uncheck it everytime the update screen pops up.
Here is how I did it with a simple script:
- Create a file (or download it below), for example 'downgrade_php.sh' and paste the following code in to it, then close the file:
#!/bin/bash # Originally Posted by Bachstelze <a href="http://ubuntuforums.org/showthread.php?p=9080474#post9080474" title="http://ubuntuforums.org/showthread.php?p=9080474#post9080474">http://ubuntuforums.org/showthread.php?p=9080474#post9080474</a> OK, here's how to do the Apt magic to get PHP packages from the karmic repositories: # # modified by Ryein C. Bowling (Cardale) <a data-cke-saved-href="http://www.kinggoddard.com" title=" href="http://www.kinggoddard.com title=" www.kinggoddard.com"="">www.kinggoddard.com December 15, 2010 echo "Am I root? " if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then echo " NO! Error: You must be root to run this script. Enter sudo su " exit 1 fi echo " OK"; # finish all apt-problems: apt-get -f install # remove all your existing PHP packages. You can list them with dpkg -l| grep php PHPLIST=$(for i in $(dpkg -l | grep php|awk '{ print $2 }' ); do echo $i; done) echo these pachets will be removed: $PHPLIST # you need not to purge, if you have upgraded from karmic: apt-get remove $PHPLIST # on a fresh install, you need purge: # aptitude remove --purge $PHPLIST #Create a file each in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php5_2); # #Package: php5 #Pin: release a=karmic #Pin-Priority: 991 # #The big problem is that wildcards don't work, so you will need one such stanza for each PHP package you want to pull from karmic: echo ''>/etc/apt/preferences.d/php5_2 for i in $PHPLIST ; do echo "Package: $i Pin: release a=karmic Pin-Priority: 991 ">>/etc/apt/preferences.d/php5_2; done # duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d: #sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list # better exactly only the needed sources, cause otherwise you can get a cachsize problem: echo "# needed sources vor php5.2: deb http://de.archive.ubuntu.com/ karmic main restricted deb-src http://de.archive.ubuntu.com/ karmic main restricted deb http://de.archive.ubuntu.com/ karmic-updates main restricted deb-src http://de.archive.ubuntu.com/ karmic-updates main restricted deb http://de.archive.ubuntu.com/ karmic universe deb-src http://de.archive.ubuntu.com/ karmic universe deb http://de.archive.ubuntu.com/ karmic-updates universe deb-src http://de.archive.ubuntu.com/ karmic-updates universe deb http://de.archive.ubuntu.com/ karmic multiverse deb-src http://de.archive.ubuntu.com/ karmic multiverse deb http://de.archive.ubuntu.com/ karmic-updates multiverse deb-src http://de.archive.ubuntu.com/ karmic-updates multiverse deb http://security.ubuntu.com/ karmic-security main restricted deb-src http://security.ubuntu.com/ karmic-security main restricted deb http://security.ubuntu.com/ karmic-security universe deb-src http://security.ubuntu.com/ karmic-security universe deb http://security.ubuntu.com/ karmic-security multiverse deb-src http://security.ubuntu.com/ karmic-security multiverse " >> /etc/apt/sources.list.d/karmic.list apt-get update apache2ctl restart echo install new from karmic: apt-get -t karmic install $PHPLIST # at the end retry the modul libapache2-mod-php5 in case it didn't work the first time: apt-get -t karmic install libapache2-mod-php5 apache2ctl restart
- Now make the script executable:
sudo chmod a+x downgrade_php.sh - Execute the script and we're done:
sudo ./downgrade_php.sh
Note:
When installing a package for php5 after this script has run we need to lock it to PHP 5.2 manually.
Here is how we do that:
- Open file '/etc/apt/preferences.d/php5_2':
sudo nano /etc/apt/preferences.d/php5_2 - Paste the following code in the file and replace 'package-name' with the package you want to install.
Package: package-name Pin: release a=karmic Pin-Priority: 991
- Update the cache of aptitude:
sudo apt-get update - Now you can install the package without any problems.
That's it, now you can enjoy your Drupal development.
Source: Ubuntu forums
Comments
Excellent. I was searching
Why not Drupal 7?
Why don't you upgrade your target platform to Drupal 7, which supports PHP 5.3? :)
If you must use PHP 5.2, I would recommend some fixes to your config.
Your proposed configuration doesn't pick security releases, and the original karmic PHP packages are vulnerable. You must use Pin: release a=karmic-security instead. You can really cut down your sources file by using http://archive.ubuntu.com/ubuntu karmic main restricted universe multiverse.
The markup in your example sources.list has some HTML markup in there, which looks wrong.
Keep in mind that Karmic (9.10) will be end of lifed come the end of April 2011, as ubuntu only supports non LTS releases for 18 months.
Why not Drupal 7
Drupal 7 is indeed fully supported, but current build site that need maintenance are still drupal 6, so we need PHP 5.2 for this.
The security pin is a good point, will that test soon and upddate if it works.
I got the sources list from the ubuntu forums and it just worked for me so I didn't feel the need to adjust it.
Karmic will indeed come to an end in April 2011, but you will still be able to use the packages (however there will be no more updates for these packages).
Don't use karmic packages
Hey,
using packages that are compiled for karmic can create problems use the repository of txwikinger instead he compiled the packages on lucid:
Have a look here: https://launchpad.net/~txwikinger/+archive/php5.2
This is the repo: http://ppa.launchpad.net/txwikinger/php5.2/ubuntu
kind regards Volkan
Karmic packages
Thanks for the tip.
Will try these repositories soon.
Greets,
Stijn
While this is pragmatic for
While this is pragmatic for the short term the real solution is to fix the compatibility problems in contrib. This is vitally important now that PHP 5.2 is officially unsupported (see http://www.php.net/archive/2010.php#id2010-12-16-1).
Good information, but...
...can't get past this line in the author's bio: "He knows everything."
Who really says or believes that about themselves, especially when it comes to technology. Sure, OK, maybe it's not meant to be taken verbatim.
Oh wait, I get it. That's a practical joke. Good one.
Indeed - we are sooooo funny
Just checkout all our bio's on http://krimson.be/about and than you'll see that we never take ourselves seriously.
Except when it comes to Drupal. We do know 'EVERYTHING' about Drupal :P
PHP 5.2 support
http://www.php.net/archive/2010.php#id2010-12-09-1
Although PHP 5.3 isn't 100% compatible with all contrib modules, I have found it's not terrible. It's also worth noting that 5.1.15 is the LAST 5.2.x release under that branch. If you downgrade to 5.2, you'll be missing out on security updates going forward.
didn't works
It didn't works.
It is not:
deb http://de.archive.ubuntu.com/ubuntu/ karmic main restricted
But:
deb http://de.archive.ubuntu.com/ubuntu/ karmic main restricted
without the "a href" section.
Don't see the difference
Hi Matthias,
I don't see a difference between the two lines..
Could it be that our input format automatically puts a href around the "http:// .. " ?
contrib module problems with PHP 5.3
I ran a test copy of my Drupal 6.19 system, with about 25 contributed modules on an Ubuntu system 10.04 LTS Lucid Lynx (with PHP 5.3) and so far it seems to be running fine. I keep hearing that some modules don't properly support PHP 5.3, but other than looking for truly obvious problems I don't know how to confirm that there are no PHP problems with my modules. Other than going to each module's page on drupal.org and looking for trouble reports or assurances that the module is ok with 5.3, is there any way to check this?
Well...
Since everyone tests on a copy of their sites on their local PC, it should be fairly easy to find them, especially if you use E_ALL.
The only errors I have seen at all merely required removing an "&" from the function definition. I suspect even non-coders can handle that fix.
This is hardly a cause for great alarm.
Don't do this. Instead, fix
Don't do this. Instead, fix the problems in the contrib modules. PHP 5.2 is end of life!
PHP 5.3 not as bad
I've had the same Drupal 6 problems in the past and wrote a less easy method to downgrade PHP at http://www.chriswiegman.com/2010/05/php-5-2-on-ubuntu-10-04/. Over time though I've found that I've been able to upgrade all my servers to PHP 5.3 with Drupal 6 without problem (overall there are a little over 100 modules being used).
My advice at this stage is to make sure you really need to downgrade. Check to make any unsupported modules are first necessary and second, if they are look for alternatives (often there is more than one module to perform a given function).
With just the above 2 steps alone you should have very few problems with PHP 5.3 and Drupal 6.
I can only echo the earlier posts
Create issues for any modules incompatible with 5.3. Keeping 5.2 alive as a private zombie is not the way.
I really think there should be a php compatibility tab on d.o's project pages to guide people in this.
Waste of time
It is interesting that so far no one has been able to name ANY popular drupal module that isn't compatible with PHP 5.3.
I have been running many high trafficed drupal sites on PHP 5.3 for more than 10 months now and I haven't encounter any issue with PHP 5.3
I feel it is unfair to keep propagating myth that Drupal 6 still doesn't work with PHP 5.3 without providing much evidence.
--
Abhi
See above
I have encountered about 3 modules with "problems." In every case, removing one "&" fixed the problem, which is actually the proper way to be coded, not really an error. Opening an issue on DO takes maybe one minute. I'd rather have the modules fixed.
Not a Community perspective
If everyone just fixed the module and did not create an issue with the fix there would be no community and you would have nothing to use.
The community is created by people spending the extra minutes so it is valuable.
Be part of the bigger picture and we all win.
Different ways of doing this ...
We outlined various ways of running PHP 5.2 with Ubuntu 10.04 Lucid Lynx and the pros and cons of each.
But for sites that don't have a lot of modules, you may be able to get away with PHP 5.3. We did just that for a huge site that has only 43 modules in total, and it runs fine. Of course, the specific modules matter more than the number of modules.
Didn't work
After I run
sudo apt-get update
I get an error message:
Malformed line 20 in source list /etc/apt/sources.list.d/karmic.list
I followed all of the instructions, however I am running 10.10 Is this the issue?
You have to download this
You have to download this file.
Then it will be ok!
http://krimson.be/sites/default/files/attachments/2011/01/04/downgrade_p...
one thing though, after
one thing though, after reverting to 5.2 with this method - installing xdebug via pecl didn't work anymore, so i had to compile it from source.
It might work to downgrade
It might work to downgrade PHP, but the better solution is still to fix the broken modules so your sites works fine on 5.3.
My personal approach to supporting both 5.2 and 5.3 on 10.04 LTS is to manually install PHP 5.2 in /usr/local on my Apache2+mod_fcgid system and point the FCGI wrapper to the 5.2 bin for sites that can't be fixed for 5.3.
And I have to say, the only sites I've had to downgrade like that are Joomla sites.
What about 1.7.1 of XAMPP?
What about 1.7.1 of XAMPP? It's like WAMP for Linux including:
Apache 2.2.11
MySQL 5.1.33
PHP 5.2.9
Here you can download the version 1.7.1:
http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.7.1/
And here are the release notes:
http://sourceforge.net/project/shownotes.php?release_id=675563
If you need to install any extension, also install the devel package to build and config with phpize.
Hope this helps!
Excellent. I was searching for information like this. Helps me a lot. Will try it.