简体   繁体   中英

Internal Server Error 500 on Apache for perl script

I have a perl script in my cgi-bin. It first prints out the following statements

print "Status: 200 OK\nContent-Type: text/html\n\n";

It generates a html form on the terminal perfectly but when I try running it on the browser it gives the following error

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

I have enabled cgi-bin in the apache configuration, the error log prints the following error

End of script output before headers

What could be the problem and how should I resolve it

You must have the Content-Type be the first thing printed back to the screen. Also make sure the script is set as executable.

print "Status: 200 OK\nContent-Type: text/html\n\n";

Should be:

print "Content-Type: text/html\n\nStatus: 200 OK\n";

The script also needs to be executable by Apache for it to work

chmod a+x YourScript.pl

I've tested with the following script and once I fixed the permissions it works just fine. You also only need to set the status if it isn't 200 as that's the default.

#!/usr/bin/perl

use strict;
print "Status: 200\nContent-Type: text/html\n\n";

print "<p>Foo</p>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM