Php – How to override mod-php5’s .php mapping to php4-cgi per VirtualHost or Directory

apache-2.2PHPphp5

I am running Debian Linux with apache2 and libapache2-mod-php5 5.3.3-7.

I have one VirtualHost which requires php4.
So I researched and compiled php4-cgi.

However, I cannot seem to:

  1. Override mod-php5's mapping of .php in that vhost (or even globally,
    without disabling php completley).
  2. Even find where that mapping is made, in hope of disabling it and enabling mod-php5 or php4-cgi per vhost.

This is my php4-cgi mapping (Inside the one php4 vhost):

ScriptAlias /php4 /usr/local/php4/bin

<Directory /usr/local/php4/bin>
  Options +ExecCGI +FollowSymLinks
</Directory>

<Directory /www/test>
  AddHandler php4-cgi-script .php
  Action php4-cgi-script /php4/php
  Options +ExecCGI
</Directory>

This does not work, mod-php5 still runs all .php files in that vhost/directory.
If I change the file extension in the AddHandler above from .php to .php4, then .php4 files do run php4-cgi as expected, but I can't change all the files in the app to .php4.

I thought maybe I could disable the mod-php5's mapping in my vhost or directory, then do my cgi-config (as above) but many combinations of these in different contexts did not work:

RemoveHandler .php
RemoveType .php
php_flag engine off (this seems to even disable my php4-cgi so that wont work)

The only other place I can find any mapping is in /etc/mime.types, but commenting out the relevant lines and restarting apache2 does not affect mod-php5's .php mapping.

I have searched as much as I can, it is now a mystery to me.

Any help or direction would be greatly appreciated.

Best Answer

The mod_php configuration by default for most linux distributions will be in the apache directory under conf.d/ and/or mods-available/ (for example: /etc/apache2/conf.d/php5.conf or /etc/apache2/mods-available/mod-php5) which is where the handler is being defined globally to the servers scope.

You will either have to alter your configuration to enable php5/php4 on a per vhost basis or define a different extension in the global server scope such as .php4 for the php4 handlers, depending on how many vhosts you have this may or may not be attractive.