thanks for the suggestion... just tried it and it didnt work. very frustrating.

as I mentioned, this error has popped up ALOT on the php mailing lists but I have yet to see anybody actually address the problem.

furthermore the folks at php.net have verly poorly documented (actually there doesnt seem to be ANY documention of) the entire process of getting apache + php as a cgi working smoothly.

any other suggestions or theories are very much appreciated.

regards,
d

    if you're running apache, then you might have suexec. could it possibly be that you haven't set the permissions correctly on your script, and suexec is returning the "premature end of script headers" because of the permission error?

    try setting your script permissions higher.

      a month later

      I share your frustration. I've been scanning the web for the last 24 hours, and nobody addresses this. Did you ever find a solution, because it may be the same one I'm searching for to fix my issue. Let me know if you found something out, and I'll let you know if I come up with something. Thanks.

      BB

        Also experienced the much dreaded "premature end of script headers" message.

        Much to my dismay, after nearly an hour of perplexing troubleshooting--to no avail-- I discovered that the file being called did not exist in the directory where it was being called. (Simple operator error.)

        Moved the file to the correct LOCATION (i.e. directory) that was being called (a .php file) and apache stopped complaining (i.e. it worked!)

        My experience would appear to equate to:
        "FILE NOT FOUND" message equivalents -- much more appropriate here than the "premature end of script headers" message. Go figure!

        C'est la vie!

          4 days later

          I was getting the same error and finally traced it back to what seems to have been the problem. It started when I added the DBG and the Java extensions to PHP 4. I commented out those lines in php.ini and I don't get the error anymore

            I followed the suggestion below and my problem has gone. I have yet to find out why exactly it happen.

            From: http://www.vbulletin.com/forum/showthread.php?threadid=6457

            They shouldn't be in your cgi-bin directory, since the server will try to execute all files in there with the perl engine. Try putting them in your root public directory, like public_html or whatever it is.

            -jim

              a month later

              Jeff is right. In my case the "premature end
              of script headers" problem was also caused
              by bad file location. It seems that the right
              translation of "premature end of script headers" announcement is "the file is missing"

              dav

                24 days later

                I was having the same problem with the simplest "hello.pl" script.

                None of the usual suspects were in error.

                I changed the first line to add "-w" to the invocation of the Perl interpreter.

                I changed it from:

                #!/usr/bin/perl

                TO:

                #!/usr/bin/perl -w

                That seemed to work. The Apache log file claimend that I had: Premature end of script headers FOLLOWED BY this error:

                (2)No such file or directory: exec of /home/htdocs/xxxxx/cgi-bin/hello.pl failed

                  2 months later

                  I was getting this error because of an infinitely recursive function.

                  I found out the problem was in the script by commenting out all the code, and then the file would display. After that, I uncommented sections at a time until I got the error again, then I knew where the problem was.

                  Anna

                    2 months later

                    YES!!!!!

                    Yay! Thank you! Thank you! Thank you! Thank you! Thank you! I just got my php apache + win95 working thank to your message!

                    :-)

                    premie end of script headers indeed ...

                      7 days later

                      I always assumed that php files had to be in the cgi-bin directory, but this seems to be incorrect! When I placed my test.php file in the htdocs directory, it worked absolutely wonderfully!! Cheers

                        2 months later

                        Include the path to the apache directory in your path-specification residing in autoexec.bat or simply copy ApacheCore.dll and Win9xConHook.dll from the Apache directory to c:\windows\system.

                        Apparently Perl, PHP and the likes don't know where to find aforementioned files when Apache invokes them (Perl, PHP, etc) to process a script (and please, let's not dwell on the fact why Apache simply generates a 'premature end of script headers' error instead of the enlightening 'file not found', shall we).

                        Hopefully, this will be the end of at least one of the many (I'm sure) inconveniences regarding the usage of php (and the likes) and apache...

                          9 days later

                          Here's a fun one. I was getting the "Premature end of script headers" running php4 as a cgi, even going so far as to copy over scripts that worked to the names of the files that gave the message, to no avail. If I switched from .cgi extension to .php (which on this server only runs php3), the scripts also worked, but I wanted to use php4 for the implementation of session variables. Turned out I had given too MUCH permissions to the aberrant cgi/php4 files. Switching from 775 to 755 (no write privileges for group) fixed the problem. I have no idea why that would be.

                            7 days later

                            LOL I just realized the problem I was having.

                            I moved a script from /dir to /dir2, & kept my browser pointed at /dir/script.php, instead of looking for /dir2/script.php.

                            :-P

                            /me smacks own forehead

                              16 days later

                              In your php.ini (in Windows, I assume there is an equivalent file in other OS's), there is a directive named doc_root.

                              I think it defaults to something like:
                              doc_root = "C:\Program Files\Apache Group\Apache\htdocs"

                              I used an Alias directive for Apache to put my scripts and html in a different directory, so this tripped up PHP. Just comment this line out to allow PHP to execute scripts from any directory, or specify the exact directories you want and it may fix this problem.

                                Vivek Raman,

                                Your suggesstion of commention doc_root worked for me too...Thanks a lot...spent lots of hrs fixing this stuff.

                                sanjay

                                  19 days later

                                  commenting out the doc_root worked for me as well.

                                  thanks

                                  tom

                                    5 days later

                                    I was experiencing the same problem when using php3 with apache.
                                    The problem was due to a misplaced php3.ini file. This file needs to be put in a directory which is part of the PATH-Variable. Otherwise the php-processor is not able to find its configuration and exits. Apache is responding with "premature end of script headers".

                                      11 days later
                                      a month later

                                      After reading this thread, I took a look at PHP's log file. PHP was reporting for me:

                                      PHP Fatal error: Unable to open (path/file.php) in Unknown on line 0

                                      So at least in my case, the issue was Apache correctly invoking PHP, but PHP could not locate the script to execute. Looks like one of several problems: permissions, path, missing script.