All cgis Premature End of Script Headers

I’m totally stack on what can be the source of this problem.

I was trying to use gitweb and I found a 500 internal server error. On tracking the error I have discovered that not only that cgi script is not working but is all cgi scripts on the server that actually doesn’t work with a 500 internal server error.

The only thing I can obtain from the logs is from the virtual server error log:

Premature end of script headers: test.cgi

The problem is not on the cgi at all as I have just tested with a hello world script, so it seems something is failing or something is blocking the execution of cgi (perl in this case) scripts before even they start execution.

Not any other logs show anything. suexec.log shows nothing related.

The virtual server runs as Fcgid and the apache configuration looks fine to me:

SuexecUserGroup “#xxx” “#xxx
DocumentRoot /home/xxxxxxx/public_html
ErrorLog /var/log/virtualmin/xxxxxxx.xxx_error_log
CustomLog /var/log/virtualmin/xxxxxxx.xxx_access_log combined
ScriptAlias /cgi-bin/ /home/xxxxxxx/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/xxxxxxx/public_html>
Options -Indexes +ExecCGI +FollowSymLinks +IncludesNOEXEC
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/xxxxxxx/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/xxxxxxx/fcgi-bin/php5.fcgi .php5

<Directory /home/xxxxxxx/cgi-bin>
allow from all

RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.) [R]
RewriteCond %{HTTP_HOST}
RewriteRule ^(.
) [R]
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 10000
FcgidMaxRequestLen 1073741824
RedirectMatch /cgi-bin/mailman/([^/.])(.cgi)?(.)$1.cgi$3
RedirectMatch /mailman/([^/.])(.cgi)?(.)$1.cgi$3
Alias /pipermail /var/lib/mailman/archives/public
Alias /dav /home/xxxxxxx/public_html
<Location /git>
DAV on
AuthType Basic
AuthUserFile /home/xxxxxxx/etc/git.basic.passwd
Require valid-user
Satisfy All
RedirectMatch ^/git$
RedirectMatch ^/git/$
RewriteEngine off
AddHandler cgi-script .cgi

<Location /dav>
DAV on
AuthType Basic
AuthName “”
AuthUserFile /home/xxxxxxx/etc/dav.digest.passwd
Require user xxxxxxx
ForceType text/plain
Satisfy All
RemoveHandler .php
RemoveHandler .php5
RewriteEngine off

Require user xxxxxxx

I don’t know where to look for more clues about the problem.


Well, that’s a good start looking in the Apache logs.

I’ve occasionally seen FCGID not showing error messages (perhaps due to it’s caching).

What you might want to do is go into Server Config -> Website Options, and change the PHP Execution Mode to “CGI”.

After doing that, and accessing one of your scripts, do you see any errors in the Apache logs?

Also, make sure that the owner of your directory and script are the same as your Virtual Server owner, as that can cause problems if the’re not.