Reverting or downgrade PHP 5.3 to 5.2 in Ubuntu Lucid Lynx 10.04

So, you upgraded to Ubuntu 10.04 but suddenly your old applications like Drupal do not work on PHP 5.3 anymore? What the hell?

Without asking why it doesn't work because we would only loose time we want to go back to the version of PHP 5.2 where it does work!

Let us list all existing PHP packages to know what version we are running:
dpkg -l | grep php

So, now we are going to duplicate the existing sources.list and replace the lucid with karmic repos and saving it in sources.list.d
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list

Create a file to be a little bit ahead of our apt-get system.
sudo nano /etc/apt/preferences.d/php
And insert the following text
Package: php5
Pin: release a=karmic
Pin-Priority: 991

Let's update the system. (You might want to do it twice to be sure)
sudo apt-get update

Installing php5 Karmic Packages. Attention! Only replace packages that were installed when doing the first command (remember the grep we did in the first step?)
sudo apt-get install php5=5.2.10.dfsg.1-2ubuntu6 php5-dev=5.2.10.dfsg.1-2ubuntu6 php-pear=5.2.10.dfsg.1-2ubuntu6 php5-cgi=5.2.10.dfsg.1-2ubuntu6 php5-cli=5.2.10.dfsg.1-2ubuntu6 php5-common=5.2.10.dfsg.1-2ubuntu6 php5-curl=5.2.10.dfsg.1-2ubuntu6 php5-gd=5.2.10.dfsg.1-2ubuntu6 php5-mcrypt=5.2.10.dfsg.1-2ubuntu6 php5-mysql=5.2.10.dfsg.1-2ubuntu6 php5-pgsql=5.2.10.dfsg.1-2ubuntu6

There you go! A fully function 5.2.10 PHP installation without troubles. If somebody knows how to make persistent so an upgrade does not replace them anymore feel free to add a comment to this post.

21 comments on Reverting or downgrade PHP 5.3 to 5.2 in Ubuntu Lucid Lynx 10.04

  1. Anonymous (not verified)
    Thu, 05/06/2010 - 14:02

    to not upgrade php 5.2 to 5.3 do this:

    echo "php5-common hold" | dpkg --set-selections
    echo "php5-cgi hold" | dpkg --set-selections
    .
    .
    .
    etc...

  2. brunodbo (not verified)
    Sat, 05/08/2010 - 15:01

    Worked like a charm, thanks.

    For others who need to do this: in order to satisfy dependencies, you may need to change Ubuntu's versioning numbers as the Karmic repository evolves (eg. use

    php5-common=5.2.10.dfsg.1-2ubuntu6.4

    instead of

    php5-common=5.2.10.dfsg.1-2ubuntu6

    To prevent the upgrade to 5.3, I needed to do:


    echo "php5 hold" | sudo dpkg --set-selections
    echo "php5-common hold" | sudo dpkg --set-selections
    ...

  3. Anonymous (not verified)
    Mon, 05/10/2010 - 22:06

    I ran into a little problem using your method. Now, all my php files are not being processed via apache, and when I access them in the browser, the browser wants me to download the actual files.

  4. Nick
    Mon, 05/10/2010 - 23:06

    Then the problem is probably that your php5 is not linked to apache
    There is a package libapache2-mod-php5. Try to install it the same way as you did with the previous packages

  5. dave (not verified)
    Tue, 05/11/2010 - 01:51

    I get an error version 5.2.10.dfsg.1-2ubuntu6 for php5 was not found

    Any ideas? I have none - this is well above my head!

    Thanks

  6. Anonymous (not verified)
    Tue, 05/11/2010 - 22:27
  7. Anonymous (not verified)
    Tue, 05/11/2010 - 22:48

    This worked. I only had the php5 package in the /etc/apt/preferences.d/file so I added all the packages I installed for PHP, and I get a working 5.2 installation. Thanks.

  8. dave (not verified)
    Wed, 05/12/2010 - 01:11

    Great, the mrkandy link above worked for me, so only one day of drupal development lost!
    thanks heaps for all the pointers
    dave t

  9. Anonymous (not verified)
    Sat, 05/15/2010 - 13:03

    Thanks for the groundwork Nick!

    Mr. Kandy: your script automated everything!!

  10. Caspar (not verified)
    Tue, 05/25/2010 - 13:33

    This worked indeed, thanks!

    One extra note, I didn't have to specify the versions in the last install-command:

    sudo apt-get install libapache2-mod-php5 php5 php5-common php5-gd php5-mcrypt php5-mysql php5-sqlite

  11. NightFury (not verified)
    Fri, 06/04/2010 - 02:16

    Nick - That was brilliant and simple. Loved how you used the built in system configuration files to make the adjustments. Nice work!

  12. Anonymous (not verified)
    Mon, 06/28/2010 - 19:37

    It worked well for me.
    there is just a package i can not install: php5-mcrypt
    when i run apt-get install php5-mcrypt=5.2.10.dfsg.1-2ubuntu6 i get this error
    E: Version â5.2.10.dfsg.1-2ubuntu6â for âphp5-mcryptâ was not found
    What's wrong?
    Thanks!!

  13. tribe_of_dan (not verified)
    Tue, 06/29/2010 - 01:12

    Same here, I get:
    E: Version '5.2.10.dfsg.1-2ubuntu6' for 'php5-mcrypt' was not found

    Anyone know how to fix this?

  14. Roger H (not verified)
    Wed, 07/07/2010 - 14:28

    I have the same mcrypt issue, and also phpmyadmin is uninstalled. having held the php5, php-common etc as described above, trying to reinstall phpmyadmin I get an error that mcrypt is a prereq but "not going to be installed"

  15. Roger H (not verified)
    Wed, 07/07/2010 - 20:50

    Fixed - used Aptitude to reinstall phpmyadmin and that sorted out mcrypt too

  16. Medden (not verified)
    Wed, 08/18/2010 - 11:21

    Anyone know how to get php5-imap working after this downgrade.
    It's telling me package not found.

  17. Nick
    Wed, 08/18/2010 - 12:26

    Try to just type apt-get install php5-imap and see if he finds anything. If you cannot do it with the command go and take a look in synaptic and look for imap. When you select the package and go to Package > Force Version you should see the possibility to install a specific version of it. Choose the 5.2.6 or higher one.

  18. Medden (not verified)
    Thu, 08/19/2010 - 15:06

    When I try that I get the message
    The following packages have unmet dependencies:
    php5-imap: Depends: phpapi-20090626+lfs
    E: Broken packages

  19. Dutchiexl (not verified)
    Fri, 08/20/2010 - 13:43

    Hi, I had the same problem with the mcrypt package. when I went to the package detail page of ubuntu i found out ir-t has another number.

    So I did

    sudo apt-get install php5-mcrypt=5.2.6-0ubuntu2

    This worked for me, I hope this helps you

  20. Medden (not verified)
    Tue, 08/31/2010 - 17:41

    That worked for me

    I ran
    apt-get install php5-imap=5.2.6-0ubuntu6.1

    Thanks for the heads up.

  21. g (not verified)
    Thu, 09/02/2010 - 08:50

    anyway... how if i wanted another php 5.2.x ?
    I suppose there's another way arround rather than compiling it from the source... right, anyone?

  22. Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options