"Premature end of script headers: php.cgi"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have compiled PHP 5.2.3 as a CGI binary, and this works. I can, for example,
do the following:

$ php.cgi hello_world.php
X-Powered-By: PHP/5.2.3
Content-type: text/html

Hello World!


However, this completely fails when I attempt to route PHP scripts through this
new CGI executable with .htaccess. My approach is this:

File: doc_root/.htaccess
AddHandler phpFive .php
Action phpFive /php.cgi

(doc_root/php.cgi links to the correct executable)

Any PHP page I visit in my browser now returns a 500 error, and the error log
contains this:

Premature end of script headers: php.cgi

It's clearly not the fault of the PHP executable itself, since it works from the
command line.


I have also tried renaming the link so it no longer has a .cgi extension.
Instead, I now get the following errors on all PHP pages.

Warning: Unexpected character in input: ' in php-cgi on line 571
Warning: Unexpected character in input: ' in php-cgi on line 571
Parse error: syntax error, unexpected ',' in php-cgi on line 571

At a wild guess, I'd say that the problem is that the server tries to interpret
the PHP executable rather than execute it as a native binary. Any ideas how I
can stop that?


Re: "Premature end of script headers: php.cgi"

Apparently, cgi WILL NOT resolve symbolic links to the binary itself  
(though directory links are resolved).

What does this mean?

The symbolic link chain that connects DOC_ROOT/cgi-bin/php.cgi to  
/MY_SOFTWARE/php/php-cgi can pass through as many links and directories  
as you want, but it may only link to the parent directory that contains  
the actual php.cgi file.

It /cannot/ link directly to the executable.

I hope that this helps anyone else who may have had this problem.

Christoph Burschka

Site Timeline