Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently I upgraded PHP to 5.4, but it seems to be failing on me because APC isn't working with it, however this gave me no choice but to downgrade to 5.3, how can I do this?

I executed apt-get remove php5 and apt-get purge php5 then I removed the 5.4 repo from apt-get then executed apt-get install php5, it says it was installing 5.3, and I restarted php-fastcgi and php5-fpm but when I run php -v it says 5.4.

How can I downgrade from 5.4 to 5.3?

My server is running Ubuntu 11.04.

share|improve this question

Downgrading PHP 5.4 to 5.3

In Ubuntu downgrading process is a really mess. Here is the script which you could find it useful (it removes PHP 5.4 and install PHP 5.3):

sudo apt-get remove --purge `dpkg -l | grep php | grep -w 5.4 | awk '{print $2}' | xargs`
sudo apt-get install php5=5.3.10-1ubuntu3.4 php5-cli=5.3.10-1ubuntu3.4 php5-common=5.3.10-1ubuntu3.4 libapache2-mod-php5=5.3.10-1ubuntu3.4
sudo apt-get install php5=5.3.10-1ubuntu3.4 php5-cli=5.3.10-1ubuntu3.4 php5-common=5.3.10-1ubuntu3.4 libapache2-mod-php5=5.3.10-1ubuntu3.4
sudo apt-get install php-pear=5.3.10-1ubuntu3.4 php5-curl=5.3.10-1ubuntu3.4 php5-gd=5.3.10-1ubuntu3.4 php5-intl=5.3.10-1ubuntu3.4 php5-mysql=5.3.10-1ubuntu3.4 php5-pspell=5.3.10-1ubuntu3.4 php5-recode=5.3.10-1ubuntu3.4 php5-snmp=5.3.10-1ubuntu3.4 php5-sqlite=5.3.10-1ubuntu3.4 php5-tidy=5.3.10-1ubuntu3.4 php5-xmlrpc=5.3.10-1ubuntu3.4 php5-xsl=5.3.10-1ubuntu3.4

Where the available versions you can check by command: apt-cache showpkg php5

After the installation, verify it by command: php --version

Please be careful and don't install any other packages without package version specified (like php5-xcache), otherwise apt-get will replace your PHP instance with 5.4 again!

To prevent this happening, you can hold these packages.

Holding packages using dpkg

To hold packages by dpkg, you can execute the following command:

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

To hold all PHP packages, run the following command:

dpkg --get-selections | grep ^php5 | sed s/install/hold/g | sudo dpkg --set-selections

The following command will show you holding status of your php packages:

sudo dpkg --get-selections | grep ^php

Holding packages using aptitude

You can also hold packages using aptitude e.g.:

sudo aptitude hold php5


sudo aptitude unhold php5
share|improve this answer
In Ubuntu 13.x 5.3.10-1ubuntu3.4 doesn't exists anymore. – kenorb Aug 1 '13 at 19:46
How would go about undoing what's in your answer? – tolgap Jun 5 '14 at 22:06
You mean go back to PHP 5.4 or recover config files? Config files should be kept as they're (no personal config should be removed). If you'd like to go back to PHP 5.4, then undo by to unhold the packages which you hold and reinstall php5 again e.g. sudo apt-get install php5 with reinstall or removal/install. – kenorb Jun 5 '14 at 22:13

First execute apt-cache showpkg php5. There you will see version and other information about the package php5.

To install a specific version run apt-get install <package name>=<version>

In my Ubuntu 11.10 it would be apt-get install php5=5.3.6-13ubuntu3.6

share|improve this answer
What if apt-cache showpkg php5 doesn't show anymore 5.3.x? – kenorb Aug 1 '13 at 19:47

I had a similar problem.

I removed the repositories.

You have to remember that php -v runs the executable in the php-cli package so you have to remove that too.

So I did the following to get back to 5.3.10:

sudo apt-get remove php5-cli php5 php5-common
sudo apt-get install php5 php5-mysql php5-curl

Now this should show the desired version:

php -v
share|improve this answer
It installs the latest 5.6 for me. – JohnnyQ Oct 4 '15 at 7:20

Maybe this guide will help you: How to downgrade a package in Ubuntu

So to download and install any package of any available version you have to do this:

sudo apt-get install Package=Version
share|improve this answer

from the steps you described, you forgot to apt-get update after purging php5.4 and removing the php5.4 repo.

assuming you don't have the repo anymore in apt sources, if you run:

apt-get remove --purge php5 && apt-get update && apt-get install php5

you should be back on 5.3

share|improve this answer
In Ubuntu 13.x, by default php5 is pointing to 5.4.x – kenorb Aug 1 '13 at 19:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.