I have compiled PHP 4.0 as a CGI binary as I don't want it as a server module.

Everything has compiled fine. The problem is when I try to view a test php script on my website. I get an Internal Server Error. The error log tells me that the error is "Premature end of script headers" Can anyone tell me why I get this?

The code I am using is:
#!/usr/bin/php

<head>
<title>Test</title>
</head>

<body>
<?php
echo("Welcome to PHP\n");
?>
</body>

Running the program from the command line gives me the output:
X-Powered-By: PHP/4.0.1pl2
Content-type: text/html

<head>
<title>Test</title>
</head>

<body>
Welcome to PHP
</body>

As you can see I get the Headers. Someone please help.

    Feed a -q parameter to your php interpreter may solve your problem, e.g.:
    #!/usr/bin/php -q

    --Hunte
    hunte@phpuser.com

      I get the same error. From what I understand the -q parameter turns off the headers. The problem seems to be that the headers are not being sent properly when accessed by the webserver.

        a month later

        I still get the same error under the following condition:

        Environment:

        RedHat 6.2
        Apache 1.3.12 mod_perl 1.21
        PHP 4.0.3-dev

        Compiled as an executable and installed in /usr/local/bin/php

        httpd.conf
        AddType application/x-httpd-php
        Action application/x-httpd-php /usr/local/bin/php

        Various other httpd.conf attemps all produce the same error:
        Premature end of script headers

        The file is mode 0755

        #!/usr/local/bin/php -q
        <Head>
        <Title>Test PHP</Title>
        </Head>

        <Body>
        <?php
        phpinfo();
        ?>

        </Body>

        I noticed on the screen that the trailing was not produced, so I added it. However, adding it or deleting it makes no difference.

        Piping output to an html file and serving it via Apache works.

        I'd really prefer running this as a DSO module, but first I would like to get it running even in CGI mode.

        I would really like this to get up and running.

        Thanks - /mde/

          6 months later

          You're probably running suexec and you haven't set it up properly? Check the suexec log.

          BTW you definitely MUST NOT use the -q switch or you certainly will get cgi errors!

            Write a Reply...