PHP4 and PHP5 per VirtualHost on the same Apache 2 webserver

Uncategorized , , , , , 1 Comment

I assume you have a working Apache 2 installation with PHP4 modules installed, if not run the following and you will have:


sudo apt-get install apache2 apache2-mod-php4

Note: you can also have PHP5 installed as module and PHP4 as CGI, everything works the same way with swapping the versions in commands.

First of all you will need the php5-cgi package, and enable the Actions module:


sudo apt-get install php5-cgi
a2enmod actions

Add a ScriptAlias directive to your apache2.conf – if you have not done this already – like this:


ScriptAlias /cgi-bin /cgi-bin

Now create the /cgi-bin directory and symlink the php5-cgi binary to /cgi-bin/php5-cgi:


mkdir /cgi-bin
ln -s /usr/bin/php5-cgi /cgi-bin/php5-cgi

Finally in every VirtualHost where you need PHP5 support put these lines:


AddHandler php5-script .php
Action php5-script /cgi-bin/php5-cgi

All you have to do is restart the apache to take changes effect and you’re done.

One thought on “PHP4 and PHP5 per VirtualHost on the same Apache 2 webserver

  • manchas rojas en la cara

    Hey there, I think your blog might be having browser compatibility issues. When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.