downgrading to PHP 5.3 on Debian Wheezy (7.0)

Debian Wheezy comes with PHP 5.4. If this is too new for your application and it doesn’t work properly, here is a short description on downgrading to PHP 5.3.

  • First, add these two lines to /etc/apt/sources.list. In short, it adds Debian Squeeze repositories as an additional source of packages:

deb squeeze main contrib non-free
deb squeeze/updates main contrib non-free


  • Then, add these to pin your old PHP 5.3 packages, to /etc/apt/preferences.d/preferences. If you don’t have this file, create an empty one.

Package: php5*
Pin: release a=oldstable
Pin-Priority: 700

Package: libapache2-mod-php5
Pin: release a=oldstable
Pin-Priority: 700

Package: php-pear
Pin: release a=oldstable
Pin-Priority: 700

Package: php-apc
Pin: release a=oldstable
Pin-Priority: 700

Package: *
Pin: release a=stable
Pin-Priority: 600

  •  This will list your PHP packages

PHP=$(dpkg -l|grep php|grep 5.4.4|awk '{print $2}')


  • Finally, reinstall:

# apt-get update

# apt-get install --reinstall $PHP
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libicu44 libjpeg62 libmagickcore3 libmagickwand3 libmysqlclient16 libt1-5 php5-suhosin
Suggested packages:
libmagickcore3-extra php5-dev
The following NEW packages will be installed:
libicu44 libjpeg62 libmagickcore3 libmagickwand3 libmysqlclient16 libt1-5 php5-suhosin
The following packages will be DOWNGRADED:
libapache2-mod-php5 php-apc php-pear php5 php5-cgi php5-cli php5-common php5-curl php5-gd php5-imagick php5-imap php5-intl php5-mcrypt php5-mysql
0 upgraded, 7 newly installed, 4 reinstalled, 14 downgraded, 0 to remove and 0 not upgraded.
Need to get 30.5 MB of archives.
After this operation, 30.9 MB of additional disk space will be used.
Do you want to continue [Y/n]?


  1. Hi,

    Good information, but why add two identical blocs of “Package: libapache2-mod-php5″ in the file /etc/apt/preferences.d/preferences?


  2. admin says:

    ctrl-v pressed twice, corrected – thanks!

  3. sameer says:


    On a fresh wheezy install do i still need to specify the package version of just doing aptitude install php5 will install php5.3

    FYI: I have done the pinning and aptitude update and aptitude show php5 shows php 5.3.3


  4. admin says:

    @sameer: as long as you follow these instruction, you should install php5-* packages.

  5. sameer says:


    It works like a charm, i have installed php 5.3.3 squeeze 14 on my system running debian wheezy, is there a way to get the security updates from squeeze for php as i have seen the latest php on debian squeeze is php5.3.3 squeeze 16

    Secondly, if in sometime i need to go back to php 5.4 what will be the process


  6. admin says:

    I think you should be getting security updates, as you have the updates repo included:

    deb squeeze/updates main contrib non-free

    If you need to go to PHP 5.4, just comment out “squeeze” lines from /etc/apt/sources.list, and update the packages.

  7. In the last commands, i got this error:
    # PHP=$(dpkg -l|grep php|grep 5.4.4|awk ‘{print $2}’)
    # apt-get install –reinstall $PHP
    Leyendo lista de paquetes… Hecho
    Creando árbol de dependencias
    Leyendo la información de estado… Hecho
    E: No se ha podido localizar el paquete –reinstall

    Can anybody help me?

  8. admin says:

    Make sure you are using “--reinstall“, and not “–reinstall”.

  9. R.Bertoli says:

    Excellent! this solved my problem when I upgraded my server to wheezy with PHP5.4 then some components in our Joomla web site like Acajoom did not worked with “error 500″ message which I could notice on the log that was a php compatibility issue, so downgraded to php 5.3 following your method and solved! Thanks!

  10. Ivan says:

    Thanks for sharing!
    What is the correct way to go back to 5.4? Without reinstalling OS, of course.

  11. admin says:

    Remove these entries, run apt-get update and apt-get upgrade (or apt-get install … to install specific php packages).

  12. Sumith Surendran says:

    Thank you so much dude you saved my ass……………

Leave a Reply