Premature end of script headers: Home.cgi


please tell me what are the causes of…
I am using Apache/2.0.40 (Red Hat Linux)

Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: Home.cgi

If you think this is a server error, please contact the webmaster
Error 500…

what could be the reason…


I don’t know the exat reasong but the following info may useful for you.

[b]Internal Server Error:

This one is nasty and gives very little information about what is going on. Here is an example.

The example script causing that error above, is a perfectly legit/valid “hello world” script, and I was able to generate this error simply by setting the permission on the file to 700 instead of 755, meaning that only the user owning the file was able to execute it, not the user the web server software runs under.
For more information on server permissions, see here.

Normally, when asked how these errors are caused, my first suggestion (or question in this case) is “what does the server error log say about it?” however in this case, the only error message in the log is: Premature end of script headers: so my advice in this case, is that if you get the internal error message the first thing you should do is check your file permissions, after all, if a script can’t execute, it can’t generate a useful error message. So, first thing to check after getting one of these error messages, is to find your servers error log, (if you don’t know where it is, you should ask your hosting provider).
If your error log doesn’t provide any useful message, the next thing to do is check your file permissions, scripts should generally have permissions of 755.
The other thing to check is how you uploaded the script, did you upload it as binary or ASCII? if its a script file like Perl, or UNIX shell, or PHP, (by script I mean a program you can open in a text editor and read the code.) you should have uploaded it as a text file (ASCII).
If the file a C or C++ or other compiled program, you should upload it as “binary”. Getting that wrong will result in a script that simply will not work, and the only recourse is to delete the file off the server and upload it again with the correct type set.

Lastly is another common problem with script files. end of line characters.
Unfortunately, windows, Unix/Linux/*BSD and Mac all have different return characters, (the characters that denote end of line or “return characters”)
This can cause problems because quite often, they are not at all compatable. In particular, windows return characters will often cause a UNIX perl or shell script to die with a relatively useless error message, because the Perl or shell interpreter doesn’t know how to “interpret” them.
More often then not, these errors are caused by editing a file on one platform, (like windows) and uploading .the file to a different platform. (like Linux).[/b]