Downgrade PHP 5.3 to 5.2

Like many others, I recently upgraded my Production server to PHP 5.3. I’m not quite sure of the reason anymore. I think I was trying to integrate a PHP profiler that required something in 5.3. Whatever my original reason, after I got 5.3 installed on my server, it started slowly hemorrhaging memory and occasionally freezing up, always during the middle of the night while I slept of course. So, today I set about downgrading PHP 5.3.2 to PHP 5.2.13. Here is what worked for me.

The Setup

First off, I’m running Ubuntu-Hardy, and both my PHP 5.3 and 5.2 distributions came from dotdeb.org. I have a Production server and a Test server that I try to keep as similar as possible. The first thing I did was make a backup of my Test server with PHP 5.3 installed and my app functional. Then I began hacking away on my Test server trying to successfully downgrade to PHP 5.2. When I screwed the Test server up beyond repair, I restored from backup. Likewise, when I made progress I documented my steps, restored from backup, and tried to repeat my success. I did this several times and eventually made a script that successfully downgraded PHP. I rehearsed this script 3 times on my Test server, backed-up my Production server, then repeated the script on my Production server. IT WORKED!

NOTICE: I probably have a couple of unnecessary steps in here that I didn’t bother to investigate their necessity. You may also need to uninstall and reinstall different PHP modules than I did, depending on the requirements of your applications.

My Final Steps

  1. Remove PHP
    1. sudo apt-get remove php5-common
    2. sudo apt-get remove php5-cli
    3. sudo apt-get remove php5
    4. sudo apt-get autoremove memcached
  2. Update your sources list to point to PHP 5.2
    1. sudo nano /etc/apt/sources.list
    2. Remove the references to PHP 5.3 packages. For me that was:
      deb http://php53.dotdeb.org stable all
      deb-src http://php53.dotdeb.org stable all
    3. Add the following 5.2 packages:
      deb http://http.us.debian.org/debian stable all
      deb http://security.debian.org/ stable/updates main contrib
      deb http://packages.dotdeb.org/ stable all
  3. Install PHP 5.2
    1. sudo apt-get update
    2. sudo apt-get install php5-cli
    3. sudo apt-get install php5
  4. Reinstall any PHP modules your application requires. For me that was:
    1. sudo apt-get install memcached
    2. sudo apt-get install php5-memcache
    3. sudo apt-get install php5-curl
    4. sudo apt-get install php5-mysql
  5. sudo reboot

After my production server rebooted, I had to fidget with Apache to get it started again. You may have to:

  • sudo /etc/init.d/apache2 restart
  • sudo /etc/init.d/apache2 stop
  • sudo /etc/init.d/apache2 start

Hope this helps!

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Tumblr
This entry was posted in IT & Administration, Web & Software Development and tagged . Bookmark the permalink.

One Response to Downgrade PHP 5.3 to 5.2

  1. Jack says:

    I’ve been encountering the same issues on my development server (and using Zend FW with PHP 5.3 seems to exacerbate the memory leak issue). I’ll have to try this and see how it goes. Thanks for sharing your downgrade script :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>