Debugging CGI Errors
Summary
What causes a CGI program to fail and what do the resulting error messages mean? This article explains the most common "server error" messages resulting from CGI programs.
Debugging Common CGI Error Messages
| If you get this CGI error message... | It may be because... | And you should... |
|---|---|---|
| Method Not Allowed - The requested method POST is not allowed for the URL | CGI program doesn't have a .cgi filename extension | Rename your CGI program so that it has a .cgi filename extension. |
| Server Error - Premature end of script headers | CGI program isn't executable | Make it executable (chmod +x filename.cgi). |
| No empty line after CGI header | Make sure the CGI program prints an empty line right after the last header (e.g. in Perl, print "Content-type: text/html\n\n";). | |
| CGI program resides in a world- or group-writable directory | Refer to Setting Unix Permissions For Web Pages to learn how to remove world or group write permission from the directory. | |
| CGI program is world- or group-writable | Remove world or group write permission (e.g. chmod go-w filename.cgi). | |
| CGI program mislocates Perl interpreter | Verify that CGI programs written in Perl begin with #!/usr/local/bin/perl on the first line. | |
| CGI program has bad end-of-line characters | Transfer all CGI programs, particularly those written in Perl, to your account using "text" mode. Binary transfers may corrupt the end-of-line characters. | |
| Server Error - malformed header from script | Error printing CGI header (e.g. a typo, Cntent-tpe: text/html) | Verify that CGI header contains no typos. |
| Program prints something before header | Debug your CGI program; make it print header first. | |
| CGI program has output buffering problems | Make sure print buffers are emptied when you think they are. In Perl, set the $| variable. |
Note: Some versions of Internet Explorer 5.x customize server error messages rather than displaying the actual text returned by the server.
Refer to Using CGI Programs to learn more about writing, installing, debugging, and securing CGI programs.
