CGI programs launched from a web server run under a fundamentally different environment than they do when invoked from the command line. While you should always verify that your CGI program runs properly from the command line, this isn't enough to guarantee that your program will work when called from the web server.
 See the CGI.pm documentation for tips on command-line debugging.
You should get the CGI programming FAQ and a good book on CGI programming to help you in this. Some of these references are listed at the end of this chapter. Here's a brief list of the frequent problems that arise in CGI programming. Almost all of them trigger those annoyingly unhelpful
500 Server Error messages that you will soon come to know and hate.
If, when sending HTML to a browser, you forget the blank line between the HTTP header (that is, the Content-Type line) and the body, your program won't work. Remember to output a proper Content-Type line (and possibly other HTTP headers) plus a totally blank line before you do anything else.
The script must be installed in the proper directory for your server configuration. For example, on some systems, the directory may be c:\inetpub\scripts.
 This directory is the default for IIS, Microsoft's Internet Information Server.
You need to have your script's filename end in a particular suffix, like .cgi or .plx, so that your web server knows that it needs to invoke the Perl interpreter on your script. Make sure that your script directory is not writable by FTP clients. We suggest using a suffix of .plx, and associating .plx with your Perl interpreter.
Normally, the web server doesn't execute your script using your account. Make sure the files and directories accessed by the script are open to whatever user the script will run as; this might be the IUSR_INTERNET or
anoynmous account, or whatever account you use on your system. You may need to pre-create such files and directories and give them appropriate permissions. Always be alert to the risks when you grant such access to files.
Always run your script under Perl's
-w flag to get warnings. These warnings go to the web server error log, which contains any errors and warnings generated by your script. Learn the path to that logfile from your webmaster and check it for problems. See also the standard
CGI::Carp module for how to handle errors better.
autoflush on the STDOUT filehandle at the top of your script by setting the
$| variable to a true value, like one. If you've used the
FileHandle module or any of the IO modules (like
IO::Socket, and so on), then you can use the more mnemonically named
autoflush() method on the filehandle instead: