Insane "Premature end of script headers"

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.

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!

Try this:


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

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

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!”).

Don’t forget your line endings for cgi output:

print “Content-type: text/html\n\n”;
print “

Hello World


note the \n entries :wink: