It seems that this is a VM bug with the way the cgi is called from a PHP script under a subdomain. It works fine for a top level domain that has the same apache virtual host configuration.
It would be easier if I could attach a couple of log and diff files to this bug report, otherwise this might get a bit messy.
Anyway, I'll keep it as brief as possible. Here's the error log (cgi mode/called from subdomain/real domain name changed):
[Thu Sep 27 18:33:25 2007] [error] [client 190.40.122.158] malformed header from script. Bad header=/var/www/virtual/mydomain.com: php5.cgi, referer: http://demo.mydomain.com/contact_us.php
And that's my virtual host configuration:
SuexecUserGroup "#1002" "#1003"
ServerName demo.mydomain.com
ServerAlias www.demo.mydomain.com
DocumentRoot /var/www/virtual/mydomain.com/domains/demo.mydomain.com/htdocs
ErrorLog /var/www/virtual/mydomain.com/domains/demo.mydomain.com/logs/error_log
CustomLog /var/www/virtual/mydomain.com/domains/demo.mydomain.com/logs/access_log combined
ScriptAlias /cgi-bin/ /var/www/virtual/mydomain.com/domains/demo.mydomain.com/cgi-bin/
ScriptAlias /awstats /var/www/virtual/mydomain.com/domains/demo.mydomain.com/cgi-bin
DirectoryIndex index.html index.htm index.php index.php4 index.php5
php_admin_value open_basedir "/var/www/virtual/mydomain.com/domains/demo.mydomain.com:/var/www/virtual/mydomain.com/domains/demo.mydomain.com/phptmp:/usr/share/php:/var/www/typo3:/var/www/virtual/typo3"
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
Action application/x-httpd-php4 /cgi-bin/php4.cgi
Action application/x-httpd-php5 /cgi-bin/php5.cgi
AddType application/x-httpd-php4 .php4
AddType application/x-httpd-php5 .php5
AddType application/x-httpd-php5 .php
allow from all
PerlRequire /etc/webmin/virtualmin-google-analytics/apachemod.pl
PerlOutputFilterHandler Virtualmin::GoogleAnalytics
RemoveHandler .php
RemoveHandler .php4
RemoveHandler .php5
If you need any additional information to trace this problem please let me now.