Downgrading PHP 5.4 to 5.3 on Ubuntu 12.10 (Quantal)

I recently upgraded one of my staging servers to Ubuntu 12.10 (aka Quantal). That’s great, except my production servers are still on Ubuntu 11.04. The idea behind having a staging environment is to match production as closely as possible. So, my choices are (a) upgrade my production systems, which is a good idea but risky, or (b) downgrade PHP on my staging servers. For various reasons relating to time and cost, I decided it would be best to temporarily downgrade PHP on my staging servers.

  1. First, I got a list of PHP-related install packages:

    $ dpkg --get-selections | grep php
    libapache2-mod-php5 install
    php-apc install
    php-pear install
    php5 install
    php5-cli install
    php5-common install
    php5-curl install
    php5-dev install
    php5-gd install
    php5-mcrypt install
    php5-memcache install
    php5-memcached install
    php5-mysql install
    php5-suhosin install

    This list will be important later, so hold on to it.

  2. While I’m looking at modules, I may as well find out what PECL modules I need:$ pecl list
    Installed packages, channel pecl.php.net:
    =========================================
    Package Version State
    oauth 1.2.3 stable
    pecl_http 1.7.4 stable

    Ok, hold on to that list too.
  3. Finally, I removed the old versions of PHP. Beware: this will shut down your apache instances!
    $ sudo apt-get remove php5 php5-cli php5-common php5-dev php-apc php-pear
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages will be REMOVED:
    libapache2-mod-php5 php-apc php-pear php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-mcrypt php5-memcache php5-memcached php5-mysql php5-suhosin
    The following held packages will be changed:
    libapache2-mod-php5 php-apc php-pear php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-mcrypt php5-memcache php5-memcached php5-mysql php5-suhosin

    Start the uninstall and hold your breath! Ok, not really. It will all be alright in the end but you will have a bit of downtime since the next steps require some time.

  4. Once the process completes, select which available version of PHP you’d like to install.

    apt-cache showpkg php5-cli
    ... Snip ...
    Provides:
    5.4.6-1ubuntu1 - phpapi-20100525
    5.3.5-1ubuntu7.11 - phpapi-20090626
    5.3.5-1ubuntu7 - phpapi-20090626

    You can see that I highlighted the PHP version I chose above. You may have more or less options available. Keep track of the package version (5.3.5-1ubuntu7) and the PHP build (phpapi-20090626).

    For most packages, the standard PHP version will be available. Some packages won’t use the same version number as the default PHP package (php5-cli), so you’ll have to re-run apt-cache showpkg for each of these. Here’s an example where the version is different, but you’ll notice that the PHP build number matches up in the dependencies section.

    $ apt-cache showpkg php5-memcache
    ... Snip ...
    Dependencies:
    3.0.6-6 - libc6 (2 2.15) phpapi-20100525 (0 (null)) ucf (0 (null)) memcached (0 (null)) php5-memcache:i386 (0 (null))
    3.0.5-1 - libc6 (2 2.7) phpapi-20090626 (0 (null)) php5-common (0 (null)) ucf (0 (null)) memcached (0 (null)) php5-memcache:i386 (0 (null))
    Provides:
    3.0.6-6 -
    3.0.5-1 -

    You’ll notice in the case of php5-memcache above, the version 3.0.5-1 matches up with the PHP build we want (phpapi-20090626), so I installed that one.

  5. Hold the package so it doesn’t get automatically upgraded on accident. Make sure to do this for each package you have installed. I’m only including a brief example for brevity.

    echo "php5-cli hold" | dpkg --set-selections

  6. Remove and install any PECL packages you need.

    $ pecl uninstall php_http
    $ pecl install php_http

  7. Check your php version

    $ php -v
    PHP 5.3.5-1ubuntu7 with Suhosin-Patch (cli) (built: Apr 17 2011 13:58:11)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

That’s it! Ok, admittedly there are a few more steps than there need to be. Also, the apt downgrade process is much easier in other ways, but this will ensure you get the correct version of PHP and each module that will meet your needs.

7 comments to Downgrading PHP 5.4 to 5.3 on Ubuntu 12.10 (Quantal)

  • Hey there I am so grateful I found your blog page,
    I really fiund you byy error, while I was browsing on Askjeeve for something else,Nonetheless
    I am here now and would just like to say thamk you for a fantastic post annd a aall round thrilling
    blog (I also love the theme/design), I don’t have time to read it aall at the minute but I have book-marked it
    and also added your RSS feeds,so when I have time I will
    be back to read a great deal more, Please doo keep up the great
    work.

  • Weeeee, what a quick and easy sonouitl.

  • Although buying a home seems like a daunting task, don’t
    forget that it’s just like buying anything else in life, only one of the bigger investments you’ll make.
    Qualified properties are identified on the Help-U-Sell
    website, . In particular, it looks as if new homebuyers will make up a lion’s share of the market as winter turns into spring.
    The types of mortgage below are the most widespread:.
    Please select the type(s) of Alerts you would like to review:.

    Know more about Home Buyers Classes and with the information of home
    buying, home selling, financing and owning real estate.

  • ServerAdmin

    I dont get php5.3.5 when I run ‘apt-cache showpkg php5-cli’
    Most likely it is problem with apt sources. Please share what sources you have in sources.list file and there order for us to get the correct version.

    Thanks

  • ServerAdmin

    I dont get php5.3.5 when I run “apt-cache showpkg php5-cli”.
    Most likely it is problem with apt sources. Please share what sources you have in sources.list file and there order for us to get the correct version.

    Thanks

  • Mitry

    Have same problem – no php-5.3 when do “apt-cache showpkg php5-cli”

  • jxn

    This is a nice walkthrough, but in my case, it looks like my only option at the “apt-cache showpkg php5-cli” step is the php version 5.4 that I just uninstalled. Any way to see more options available? Would I need to load in some other repository?

    Thanks

Leave a Reply