SubDomains and PHP5 cgi


We use php5 as CGI and we have a problem with sub domains.

I explain :

Here is our config

AddHandler x-httpd-php5 .php5
Action x-httpd-php5 /php5/php-cgi

Then in every vhost we have set a ScriptAlias corresponding to the Action directive (which as to use a scriptalias), like this

ScriptAlias /php5/ /home/account/

In this directory we have a copy of the php cgi binary (php-cgi)

Everything work well as long as we stay in the main domain. The problem is with the subdomains. For exemple we created a subdomain sub1 wotks great works great

But doesn’t work. We have an error 404 Not found like this

The requested URL /php5/php-cgi/index.php was not found on this server

It’s look like the rewrite rules about subdomain bypass the ScriptAlias directive. Indeed, it looks like for /php5/php-cgi/index.php. So it is in subdomain. If we create a dir php5 in this subdomain with the php-cgi bin it is much better but as we don’t have a scriptAlias the execution of CGI is not allow there

Well, how to allow CGI in a subdomain by using the Action directive (to not have to enter in very php5 script #!/home/account/ like we’ll do with a perl script ?)

Thanks for your help


In fact the question remain with CGI too…

How is it possible to rubn a cgi from a subdomain ?

I mean, if I create a dir called cgi-bin in my subdomain then copy the php binary in it and change my config to have

AddHandler x-httpd-php5 .php5
Action x-httpd-php5 /cgi-bin/php-cgi

and in my vhost conf file

ScriptAlias /cgi-bin/ /home/account/

Then it won’t work too.

So how is it possible to run a cgi script in a subdomain ?


Ok the problem has been solved by installing SUPHP

If you like I can give you a SRPM of suPHP0.6.1 that will work well with our other SRPM php-5.1.2-cgi-cli ( and which will gibe you the ability to easily have on an interworx box php running as:

  • php4 as module or cgi
  • php5 as CGI
  • More security (mod suPHP in paranoid mode + suexec)

The config file of suphp.conf in /etc/httpd/conf.d/suphp


LoadModule suphp_module modules/

<IfModule mod_suphp.c>
suPHP_Engine off

Vhost config file of the user who’d like to have php5 and php4 in /etc/httpd/conf.d/domain.conf


AddHandler x-httpd-php .php
AddHandler x-httpd-php5 .php5
suPHP_Engine on
suPHP_UserGroup user group
suPHP_AddHandler x-httpd-php5 .php5
suPHP_AddHandler x-httpd-php .php
php_admin_flag engine Off

<Files *.php> # ini php file for php4 /etc/php.ini
suPHP_ConfigPath /etc
<Files *.php5> # ini php file for php5 /etc/php5/php.ini
suPHP_ConfigPath /etc/php5

and finaly the suphp.conf in /etc


;Handler for php-scripts


By default all file in the docroot ending by .php5 will be treat by suPHP handlers and the php5 binary, and all file ending by .php will be treat by suPHP handlers the php4 binary

If your users want to have all their files ending by .php treat by suPHP and php5 bianry just tell them to add in an .htaccess file this

AddHandler x-httpd-php5 .php
AddType application/x-httpd-php5 .php

Hope this will help


another thought that I had was to create a separate virtual host in the same vhost config file for but it sounds like your idea is better.

In fact Tim I tried this too, but the problem was that the script need some files hosted on the main domain. This script is DotClear2 and it allows to create mutliple blog, so we use it to give blogs to our clients like

DotClear2 needs php5 it’s why we did the srpm which install only the cgi and cli version of php5

The inconvenient with suPHP is that as soons as you enable it in a vhost the php4 DSO module doesn’t work anymore on this vhost. You have to use both php4 and php5 as CGI with the suPHP_Handler. The main advantages is that the user might control what he wants via .htaccess file, like .php as php5 and .php4 as php4 or .php as php4 and .php5 as php5. The other advantage is that you don’t have to copy the php binary in the vhost, suPHP use the standard bianary location and suexec still works

So to conclude this solution is quiet good indeed


Interesting info – Glad you made it work :smiley:

Similar issue with PHP4 as a CGI and PHP 5 as a module on my server.

I’ve found I can use PHP4 as a CGI via an .htaccess file at the root level of the site. PHP4 is then propagated throughout the site sub-domains and sub-folders, but can be overridden on any sub-domain or sub-folder by placing another .htaccess file that calls the PHP5 module. This way I don’t have to touch the virtual host file :