Install PHP4 and PHP5 on Linux Debian

As it took me quite a lot of time to do this, I’ll post it here so I can find it later if needed.

I tried it on Squeeze but it should be OK on Wheezy too.

We can’t install both PHP 4 and PHP 5 as Apache module. So what we’re going to do is install PHP 5 as Apache module and PHP 4 as CGI.

First, install apache 2.

Secondly, install MySQL server and phpmyadmin if needed.

Then, don’t forget to install FCGID for Apache

Hardest part now : install PHP 4. You can’t imagine how many hours I waste onto trying to install this old s****. But I clearly had no choice.

There is a nice dude which shares packages of PHP 4 online. The best part is, you can add it as a repo for apt.

Packages are there for 64bits versions : http://www.cecak.cz/debian/squeeze/php4/amd64/

Then, just edit you /etc/apt/sources.lists and add

In a terminal, go for

Then you’re good to go !

And then all extensions you need :

Now, let’s tell Apache to use PHP 4 on a separate virutal host, so you keep PHP 5 by default and PHP 4 only on a special address.

I just copied the default site config. You can call the new file whatever you want.

My virtual host files will be stored in /var/www/php4. My config file looks like this :

The most important part is FilesMatch, which will tell Apache to use PHP CGI (PHP 4 here) to execute php files.

Save the file and enable it using

Then restart Apache so it takes all modifications into account.

Last part, we need to edit /etc/hosts file to add our virtual host address to point it to localhost. Simply add

at the end of the file.

Now you should be good to go !

You can show php version putting this code

into a file and go for it into your browser.

Published by

Louwii

Web developer, geek, car enthusiast, photographer, DIYer, video gamer... I like many things, maybe too many?

2 thoughts on “Install PHP4 and PHP5 on Linux Debian”

  1. /etc/apt/sources.lists

    Es heißt: /etc/apt/sources.list (ohne s)
    funktioniert auf Debian 7 nicht:
    apt-get install php4-cgi
    Paketlisten werden gelesen… Fertig
    Abhängigkeitsbaum wird aufgebaut.
    Statusinformationen werden eingelesen…. Fertig
    Einige Pakete konnten nicht installiert werden. Das kann bedeuten, dass
    Sie eine unmögliche Situation angefordert haben oder, wenn Sie die
    Unstable-Distribution verwenden, dass einige erforderliche Pakete noch
    nicht erstellt wurden oder Incoming noch nicht verlassen haben.
    Die folgenden Informationen helfen Ihnen vielleicht, die Situation zu lösen:

    Die folgenden Pakete haben unerfüllte Abhängigkeiten:
    php4-cgi : Hängt ab von: libdb4.8 ist aber nicht installierbar
    Hängt ab von: libssl0.9.8 (>= 0.9.8m-1) ist aber nicht installierbar
    E: Probleme können nicht korrigiert werden, Sie haben zurückgehaltene defekte Pakete.

Leave a Reply

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