gszabo has asked for the wisdom of the Perl Monks concerning the following question:
Hello
I have installed an IPAM system (Gestioip)to my server ( Debian7, apache 2.2 ) it starts with an .sh script, it downloads the modules, copy the files, made config files.
The script downloads perl modules, and create an apache config.
opening it in a browser generates this error in apache.log
Tue Sep 29 09:44:05 2015 error client 10.10.10.2 Premature end of script headers: index.cgi
Permissions of files, directories, the perl script is okay, i installed the program in virtual machine succesfuly in similar enviroment.
How can i debug this error?
Thanks for your help
Re: Premature end of script headers
by dsheroh (Monsignor) on Sep 30, 2015 at 07:23 UTC
|
The one thing that a CGI script absolutely must do is emit a header block which contains a Content-Type header and ends with a blank line. If your code fails to do so, it triggers the "premature end of script headers" error.
So that's the problem. How do you debug it?
I'd start by looking at the apache logs a little more, to see if there are any obvious Perl/shell errors immediately before or after the "premature end of script headers" line. If there are no Perl/shell errors there, then the program ran successfully (or at least it thought it did) and exited cleanly, but the output didn't contain the required header block, so I'd run the code from the command line to verify that:
- The output includes the line Content-Type: text/html (or whatever the appropriate content type might be) and possibly some other headers
- The headers are followed by a blank line, even if they are the only output
- There are no non-header lines prior to the blank line
- The output described above is sent to STDOUT, not STDERR. (This is unlikely to be a problem in practice, since I would have already seen the output in the apache log if it was sent to STDERR. Still doesn't hurt to double-check, though.)
Actually, re-reading the question, it sounds like you may have an installation script which was intended for command-line use, and you're running it with CGI instead. If that's the case, then there's a good chance it ran just fine and the only problem is that it didn't bother to print the HTTP headers, since it didn't expect to be run in an environment where they're needed. | [reply] [d/l] [select] |
|
thank you for the reply.
I run the script command-line, and found no error.
perl -c -T /var/www/gestioip/install/index.cgi
/var/www/gestioip/install/index.cgi syntax OK
| [reply] |
|
-c doesn't run the script, it just compiles it. Try running it without the option and check the output as described in the previous post.
| [reply] [d/l] |
|
|
|
|
|
#!/usr/bin/perl -T -w
use strict;
#comments till line 27
my $lang;
if ( $ENV{'QUERY_STRING'} ) {
$ENV{'QUERY_STRING'} =~ /.*lang=(\w{2}).*/;
$lang=$1;
my $fut_time=gmtime(time()+365*24*3600)." GMT";
my $cookie = "GestioIPLang=$lang; path=/; expires=$fut_time; 0
+";
print "Set-Cookie: " . $cookie . "\n";
} elsif ( $ENV{'HTTP_COOKIE'} ) {
$ENV{'HTTP_COOKIE'} =~ /.*GestioIPLang=(\w{2}).*/;
$lang=$1;
}
if ( ! $lang ) {
$lang=$ENV{HTTP_ACCEPT_LANGUAGE};
$lang =~ /(^\w{2}).*/;
$lang = $1;
}
my $config;
if ( $lang eq "es" ) {
$config="./vars_es";
} elsif ( $lang eq "en" ) {
$config="./vars_en";
} elsif ( $lang eq "de" ) {
$config="./vars_de";
} else {
$config="./vars_es";
}
open(CONFIG,"<$config") or die "can't open $config: $!";
my %preferences;
while (<CONFIG>) {
chomp;
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$preferences{$var} = $value;
}
close CONFIG;
print <<EOF;
Content-type: text/html\n
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head><title>$preferences{title}</title>
The Great Programmer is one who inspires others to code, not just one who writes great code
| [reply] [d/l] [select] |
Re: Premature end of script headers
by Discipulus (Canon) on Sep 30, 2015 at 07:41 UTC
|
| [reply] [d/l] [select] |
|
update
The script is index.cgi, copied by the install.sh script. the script is okay, i can run it in a virtual debian with similar settings ( apache, perl version )
Checked apache logs and found this line only nothing else.
Tue Sep 29 08:55:54 2015] [info] [client 10.10.10.2] Connection closed
+ to child 3 with standard shutdown (server my.test.gestio.hu:443)
[Tue Sep 29 08:55:56 2015] [info] [client 10.10.10.2] Connection to ch
+ild 4 established (server my.test.gestio.hu:443)
[Tue Sep 29 08:55:56 2015] [info] Seeding PRNG with 656 bytes of entro
+py
[Tue Sep 29 08:55:56 2015] [info] Initial (No.1) HTTPS request receive
+d for child 4 (server my.test.gestio.hu:443)
[Tue Sep 29 08:55:56 2015] [error] [client 10.10.10.2] Premature end o
+f script headers: index.cgi
[Tue Sep 29 08:55:56 2015] [info] [client 10.10.10.2] Connection close
+d to child 4 with standard shutdown (server my.test.gestio.hu:443)
[Tue Sep 29 09:43:56 2015] [info] [client 10.10.10.2] Connection to ch
+ild 5 established (server my.test.gestio.hu:443)
[Tue Sep 29 09:43:56 2015] [info] Seeding PRNG with 656 bytes of entro
+py
[Tue Sep 29 09:43:56 2015] [info] Initial (No.1) HTTPS request receive
+d for child 5 (server my.test.gestio.hu:443)
[Tue Sep 29 09:43:56 2015] [info] [client 10.10.10.2] Connection close
+d to child 5 with standard shutdown (server my.test.gestio.hu:443)
[Tue Sep 29 09:44:00 2015] [info] [client 10.10.10.2] Connection to ch
+ild 9 established (server my.test.gestio.hu:443)
[Tue Sep 29 09:44:00 2015] [info] Seeding PRNG with 656 bytes of entro
+py
[Tue Sep 29 09:44:05 2015] [info] Initial (No.1) HTTPS request receive
+d for child 9 (server my.test.gestio.hu:443)
[Tue Sep 29 09:44:05 2015] [error] [client 10.10.10.2] Premature end o
+f script headers: index.cgi
[Tue Sep 29 09:44:05 2015] [info] [client 10.10.10.2] Connection close
+d to child 9 with standard shutdown (server my.test.gestio.hu:443)
I try to run another .cgi perl script, but get the same error always.
i do not use fasrcgi or suexec, i have read they could made similar errors.
I have a goog running system as well with this script, so i just need to figure out the difference what cause this error. | [reply] [d/l] |
|
| [reply] |
Re: Premature end of script headers
by Anonymous Monk on Sep 30, 2015 at 07:11 UTC
|
| [reply] |
Re: Premature end of script headers
by gszabo (Novice) on Sep 30, 2015 at 10:22 UTC
|
try to put a test.cgi script in www dir with this :
#!/bin/sh
echo "Content-type: text/plain"
echo
set
It generates the same error in error.log
| [reply] |
Re: Premature end of script headers
by gszabo (Novice) on Oct 02, 2015 at 07:50 UTC
|
Thank you for the help guys, finaly i solved it.
That was the problem:
http://blog.gmane.org/gmane.comp.apache.mod-log-sql/month=20080701 | [reply] |
|
|