Premature End of Script headers in Apache
Visited 111 times, 1 so far today Linux VPS Hosting Add comments
There are two main reasons for the error “Premature End of Scripts headers”. This is an attempt to elaborate more on those reasons.
When running a Perl CGI script, you may see the “Internal Server Error” message in your browser. When you come across this, you should check the server logs to get the exact reason for this error. A good place to look for is in the Apache error log, which is generally located at /usr/local/apache/logs/error_log or /usr/local/apache/logs/suexec_log
The other interesting cause of this error is suEXEC problems.
Assuming that your server is configured properly for running CGI scripts, your problem may be one of these common causes for the Internal Server Error:
Problems outside the script:
1. Directory permissions: your cgi-bin directory should be chmod’ed as 0755, not 0777. Similarly if your script is at …/cgi-bin/foo/bar.cgi, the foo directory must not be world-writable (0777). This is because many servers will refuse to execute CGI scripts within world-writable directories, as a security precaution.
2. File permissions: your CGI script itself must also be 0755 and not 0777, for the same reasons.
3. Transfer modes: if you are using FTP to transfer the CGI script to your server, then your FTP client is probably set to AUTO transfer mode; that is, it will try to figure out whether to use BINARY or ASCII mode without asking you. But depending on whether your CGI script came from a Windows or UNIX system, and whether it’s going to a Windows or UNIX system, you may need to manually set your FTP client to use either ASCII or BINARY mode before transferring your CGI script. Try one and then the other.
4. Line endings: the cause of the transfer-mode problem is actually another problem in itself: different types of Operating Systems (namely, Windows vs. UNIX/Linux/everything) use different character codes to represent line-endings. If your server is a UNIX server, but you’re editing your CGI script on a Windows computer with a text-editor that doesn’t use UNIX-style line-endings, it’ll cause problems. Applications like GoLive and Dreamweaver sometimes get this wrong. Even built-in editors can’t agree: WordPad (not Word) seems to get it right while Notepad messes it up. So try opening & saving your CGI script in a different text editor and uploading it to the server again.
5. htaccess File : Incase of Linux Systems you need to check the .htaccess file also, for the deny IP statements. Due to this line in the htaccess file the error is premature end of script headers .
Problems within the script:
1. The shebang line: The first line of a CGI script must contain the path to the Perl binary on the server. On most UNIX servers this is just #!/usr/bin/perl or sometimes #!/usr/local/bin/perl and you can always run the command “which perl” to find out for sure. On Windows servers, you can sometimes get away with just using #!perl but you may need to specify the full path like #!c:\path\to\perl.exe.
2. Actual script errors: it’s always possible that there’s simply an error in the Perl code itself. If you’re having trouble with a script you purchased from Encodable Industries, this is unlikely since many other people have bought the same exact script and are running it just fine.
Related Problems
1. Premature end of script headers: /usr/local/cpanel/whostmgr/docroot/cgi/addon_cmq.cgi: Please check /usr/local/cpanel/logs/error_log for the exact error.
Exact Error –
Can’t locate loadable object for module Template: Stash::XS in @INC (@INC contains: /usr/local/cpanel /usr/lib/perl5/5.8.8/x86_64-linux /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/x86_64-linux /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl . /usr/local/cpanel/whostmgr/docroot/cgi) at /usr/lib/perl5/site_perl/5.8.8/Template/Stash/XS.pm line 31
BEGIN failed–compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Template/Stash/XS.pm line 31.
Compilation failed in require at /usr/local/cpanel/Cpanel/Template.pm line 14.
Solution:-
In this case just reinstall the perl module Template::Stash::XS . This will fix this issue
- Re-upgrade perl
- Re-run the CSF installation script
- Change the cPanel update settings
If reinstalling perl fixes it, then it’s a cPanel problem and you will need to reinstall it on your servers.














November 25th, 2008 at 6:59 am
If you receive this error “Premature End of Script headers” while accessing PHP files, then check the size of error_log file, which is under “/usr/local/apache/logs/error_log”.
Echo the file contents.
# ll -ah /usr/local/apache/logs/error_log
# cd /usr/local/apache/logs/
# echo > error_log
This should fix the issue.