Re: How to get over 'premature end of script headers' in Apache?⭐
by davorg (Chancellor) on Jul 26, 2000 at 15:36 UTC
|
This message says "your script broke and it didn't send any HTTP headers before sending the error messages". Some suggestions for further investigation:
- Check the error message that was written in your apache error log.
- Switch off output buffering (set $| to a true value) to ensure that headers get out before your errors.
- Put use CGI::Carp qw(fatalsToBrowser) to make debugging easier (but remove it before putting the script live).
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?⭐
by le (Friar) on Jul 26, 2000 at 15:32 UTC
|
print "Content-type: text/html\n\n";
or
use CGI;
print header();
| [reply] [d/l] [select] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on May 26, 2004 at 09:41 UTC
|
If you developed this script on Windows, it's possible that the script file has non-UNIX line endings. (The perl interpreter can handle them, but the shebang line is interpreted by the shell, and is not tolerant of incorrect line endings.) If this is the problem, the script may terminate with an error right at the shebang line.
When you bring a script over to UNIX from other OSes, check the file format, and correct line endings if necessary.
For example, using vi, when you open the script the file format is displayed at the bottom of the window. To force the file to UNIX format, enter the vi command
:set fileformat:unix
| [reply] [d/l] [select] |
|
You can also use cat -A to check the line endings. If you see anything but #!/usr/local/bin/perl$, you've got the wrong line endings, and need to use dos2unix or perl -pi -e 's/\r\n/\n/g' foo.pl.
| [reply] [d/l] [select] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Oct 03, 2003 at 07:58 UTC
|
Make sure there's an empty line after the HTTP headers (such as "Content-type:") and before the body text. For example, print "Content-type: text/html\n\n";
Forgetting that empty line will result in a "500 Server Error" being sent to the client, and a "Premature end of script header" message being written to the server error log, so it could be the source of your problem.
| [reply] [d/l] |
Re: How to get over 'premature end of script headers' in Apache?
by wardk (Deacon) on Aug 21, 2002 at 20:36 UTC
|
For debugging purposes, you can try running the script from the command line;
then you will see exactly what the program is outputting.
If using CGI.pm, you can pass in any required parameters to replicate
form input:
scriptname fee=fi fo=fum foo=bar
| [reply] [d/l] |
|
That will definitely help, but you need to make sure that the environment is identical to the one the webserver is using. Webserver accounts tend to be very restricted, moreso than human accounts.
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by TheThinker (Initiate) on Jan 27, 2005 at 19:44 UTC
|
This can be caused by the suexec wrapper in Apache.
Check the suexec logs for the real error message,
as the Apache log will only show a generic message.
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Apr 13, 2004 at 01:25 UTC
|
If you are uploading the file to a server via FTP, make sure that you are uploading as ASCII and not binary. | [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by jundy (Initiate) on Apr 01, 2005 at 01:07 UTC
|
This may seem a little obvious, but make sure that your script produces valid output no matter what the input.
(I say this from first-hand experience ;-)
Even if you think that you have thought of every conceivable scenario, make sure that you have a default behavior "just in case".
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Aug 21, 2002 at 17:26 UTC
|
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Jun 14, 2004 at 20:48 UTC
|
| [reply] |
RE: How to get over 'premature end of script headers' in Apache?
by Mushy (Scribe) on Aug 16, 2000 at 23:54 UTC
|
| [reply] [d/l] [select] |
Re: How to get over 'premature end of script headers' in Apache?
by tsayman (Initiate) on Jun 04, 2007 at 21:19 UTC
|
Another possibility is to make sure the shebang line isn't indented. | [reply] |
Re: How to get over
by frodo (Initiate) on Jul 26, 2000 at 16:11 UTC
|
#!/usr/bin/perl
print "Content-type:text/html\n\n";
#html - document itself
It's really shame for me not to use CGI.pm.
But I'm too new in Perl programming. I've checked all my servers log - and only one error is there - "Premature and of script headers". And sometimes I get from perl errors that I'm trying to write on closed handler while it's full nonsense!!!But still he(perl) is writing in them . Bur this is not the main problem. Thank's to davorg - I'kk try everything he said about
Originally posted as a Categorized Answer. | [reply] [d/l] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Jul 02, 2004 at 15:21 UTC
|
Debian users should see if they may be affected by
bug #161639.
| [reply] |
Re: How to get over
by frodo (Initiate) on Jul 26, 2000 at 16:13 UTC
|
#!/usr/bin/perl
print "Content-type:text/html\n\n";
#html - document itself
It's really shame for me not to use CGI.pm.
But I'm too new in Perl programming. I've checked all my servers log - and only one error is there - "Premature and of script headers". And sometimes I get from perl errors that I'm trying to write on closed handler while it's full nonsense!!!But still he(perl) is writing in them . Bur this is not the main problem. Thank's to davorg - I'll try everything he said about
Originally posted as a Categorized Answer. | [reply] [d/l] |
Re: How to get over 'premature end of script headers' in Apache?
by Anonymous Monk on Jul 27, 2000 at 08:09 UTC
|
Re: How to get over 'premature end of script headers' in Apache?
Originally posted as a Categorized Answer. | [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by TheThinker (Initiate) on Jan 18, 2005 at 16:57 UTC
|
| [reply] |
Re: How to get over 'premature end of script headers' in Apache?
by sherab (Scribe) on Mar 13, 2014 at 14:32 UTC
|
chcon -R -t httpd_sys_content_t /usr/local/web/cgi-bin
It changes security context recursively on /usr/local/web/cgi-bin/.
| [reply] [d/l] [select] |
Re: How to get over 'premature end of script headers' in Apache?
by mrjcleaver (Initiate) on Jan 21, 2005 at 09:27 UTC
|
| [reply] |