Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

While there are many answers about running php5 and php4 together I haven't found answers that address my specific scenario.

I setup a new Ubuntu 12.4 server installed apache 2 and PHP 5.3. I have a need to run php 4.4.9 due to having to work with an old CMS system was written long ago, still maintained and encounters errors when run via php5.

So php5 is running as an apache module.

I want to run php4 and everything points to having to run that as cgi. I've seen the solutions where people had to change file extensions to .php4 and run them through cgi handler, but I don't have that as an option for either php4 or php5. Too many files and the codebase is shared.

First question, can I install php4 as a module as well? followup, what's best way to do that?

second question, can I have the handler that switches to php4 do so on a directory path instead of just *.php4? So I could tell it a list of directories or use multiple <Directory> blocks to have just php files in those directories run as php4.

thanks, - keith

share|improve this question

php4 and php5 are incompatible with each other. You will either need to use the old, unsupported version (which you will ahve to build from source), or use php5 and update your systems. You cannot run them both simultaneously without breakage.

share|improve this answer

You could set up php4 to run under a different webserver entirely, either apache 1.3 or lighthttpd. Just set that webserver to listen on a different port (not port 80), and either use that directly or set up some amount of rewriterules in apache2 to direct the php4 requests to the other webserver.

That would be a lot of work and setup though, potentially more than just using CGI.

share|improve this answer

For the first question, I don't believe this is wise even if possible - which it may be, I don't know anyone who has tried it.

For the second question, you can indeed do this.

However, you need to tell Apache which handler to use for the folders containing your PHP4 application.

The normal way to make php4 run as cgi is:

Add Handler php-script .php4
Action php-script /cgi-bin/php4

But this isn't quite what you want so we need to change to something like this:

RemoveHandler .php 
Add Handler php-script .php
Action php-script /cgi-bin/php4

You may need to add an ExecCGI option to the applications root folder too.

I can't test that at the moment so there's a chance it wont work. As an alternative, you could put in a rewrite that changed all .php file requests to .php4

Note that this is all dependent on having sufficient rights to make these changes either in a .htaccess file or in an apache conf file (which requires rights to restart the apache server).

UPDATE: the more I think about my answer the less I think it will work. Checking the mod_php5 conf file, I can see that the handler is actually set against a mime type application/x-httpd-php so you'd have to adjust that as well I think.

So maybe the rewrite is best.

There is another possibility though. If you have access to the apache configuration files, you could empty /etc/apache/mods-available/php5.conf and move the contents into a site specific configuration. Then you could put a php4 specific configuration into another virtual host or even into a folder - though in that case, you'll probably need to include the php5 config in several places (for each application root folder on your web server).

UPDATE 2: In fact, the answer to quesition 1 is also "yes", this is, in fact possible. You can run both by making use of suPHP. Though you should read about the possible limitations of running PHP this way.

share|improve this answer

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.