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
- Remove PHP
- sudo apt-get remove php5-common
- sudo apt-get remove php5-cli
- sudo apt-get remove php5
- sudo apt-get autoremove memcached
- Update your sources list to point to PHP 5.2
- sudo nano /etc/apt/sources.list
- 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
- 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
- Install PHP 5.2
- sudo apt-get update
- sudo apt-get install php5-cli
- sudo apt-get install php5
- Reinstall any PHP modules your application requires. For me that was:
- sudo apt-get install memcached
- sudo apt-get install php5-memcache
- sudo apt-get install php5-curl
- sudo apt-get install php5-mysql
- 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!
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 🙂
nope… didnt work for me 🙁 thanks anyway 🙂
Worked great for me. Thanks.
Worked for me , great Thanks !!!!!!!
Uninstall seemed to work fine, but it went right back to the same 5.3.2. Do you have any updates to this that might help?
#!/bin/bash
#Script to install PHP 5.2 from 9.10 on 10.10
# And pin it so it does not get updated
PKGS=`dpkg -l | grep php | awk ‘{print $2}’`
apt-get remove $PKGS
sed s/maverick/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
You inspired me for a simpler way:
– find out packages which came from php5.3:
dpkg -l | grep php | grep “5.3” | awk ‘{print $2}’
– Use apt pinning: Add those packages to /etc/apt/preferences, like
Package: php5
Pin: release a=oldstable
Pin-Priority: 996
– Add as the last entry in /etc/apt/preferences:
Package: *
Pin: release o=Debian
Pin-Priority: -1
-Use apt-cache policy php5 before installing to see if your pinning was successful
– Pretend to reinstall those packages found in the first step in simulation mode:
apt-get install –simulate -t lenny –reinstall
– Include all php5 related package the system wants to remove in /etc/apt/preferences the same way as described above
– Retry reinstallation simulation and repeat apt pinning until no more packages you really need, would be removed
– Do the reinstallation (suppress the –simulate switch)
– Find out which additional packages from lenny are needed: Watch the logs for error messages, stating a file was not found. Search the corresponding package and pin and install it (or scroll back in your terminal, if you still have the messages from the unlucky upgrade to php5.3)
Like this I could downgrade php to 5.2 and let my horde and roundcube installation run under squeeze.
Please correct, if this is incomplete or wrong.
Evidently you need both dists lenny and squeeze in your sources.list for the above to work.
I am using ubuntu server 10.04. Works great for me! Now I can see at http://server_ip/info.php that PHP version switch from 5.3 to 5.2. Thanks!
Somehow on my sever now works nothing… tried many things and I guess I broke everything now… 🙁
I think, already in the repository is also php5.3
I m using Ubuntu 10.10 (maverick)…suggest me a way to downgrade from PHP 5.3 to 5.2??I have tried a lot of scripts ….none worked !!
is there easy way to downgrade from php5.3 to 5.2 ?
I just upgrade to 5.3, and all my stuff are screwed now..