Insane "Premature end of script headers"

software development

#1

I’ve got PERL scripts running on my site in my /cgi-bin as we speak. Today I tried adding a new one: prints.cgi (the name isn’t important, as you’ll see). I upload it, chmod 755, try to run it from the web: 500 Internal Server Error. I look in the error.log: Premature end of script headers."

All right. I write a little Hello World script.

#!/usr/bin/perl
print “Hello world!”;

I upload that, chmod 755, try to run from the web. 500 error, premature end of script headers.

I telnet in and run it with “perl helloworld.cgi” just to see if it’ll run in SSH. It does! But it won’t run from the web.

What kills me is I have lots of other scripts currently running in that same /cgi-bin directory that run from both command line and the web, with no trouble. But I can’t seem to add a single new one!! Help!


#2

Try this:

#!/usr/bin/perl

print “Content-type: text/plain\n\nHello world!”;

I think the error is due to the lack of Content-type header information.


#3

Nope. Still throws 500 from the web, and runs from command line fine (except this time, the output was “Content-type: text/plain Hello world!”).


#4

Don’t forget your line endings for cgi output:

#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print “

Hello World

\n”;

note the \n entries :wink:

–rlparker