Note: This file has moved to notablog.
CGI/Perl Basics The basic requirements to have and run a CGI/Perl script are: 1) execute permission enabled 2) located cgi-bin directory and/or has proper suffix 3) has proper #! line 4) code is syntactically correct, compiles cleanly 5) imports CGI module 6) outputs intelligible HTML To go into these in a bit more detail: 1) execute permission enabled Most web servers are run on unix-flavored operating systems. This means that they generally won't let you run a file as a program unless you explicitly tell the operating system that file is meant to be executed, using the chmod command. For a really quickie intro to this topic, read http://darksleep.com/puff/writings/unixpermissions.txt 2) located cgi-bin directory and/or has proper suffix Now that the operating system knows it's all right to run your file, you need to make sure the web server knows it's all right. How you do this depends on your web server and on the configuration choices your system administrator made when he or she installed your web server. With Apache, the most popular web server, you typically do this either by putting the file somewhere under a special directory, typically named "cgi-bin", or by giving the file a specific suffix, typically ".cgi", like "foo.cgi". This is controlled by the httpd.conf file, which is typically located somewhere like "/etc/apache/httpd.conf". The keywords to search for are "ScriptAlias" and "handler". The ScriptAlias directive controls which directories are allowed to contain scripts, while handlers are the general mechanism for giving a file special treatment depending on its suffix. 3) has proper #! line Executable files have to contain either machine code, or some sort of pseudo-english "scripting" language code. If it's a script, the first line has to be something like: #!/usr/bin/perl The operating system uses this to figure out what program to run to interpret the commands and on-the-fly translate them into machine operations. The key things are to make sure you have this line and to make sure that the interpreter it points it is really there. You also might want to check and make sure that version of perl is correct (by entering "/usr/bin/perl -v" from the command line) for the script you're running. 4) code is syntactically correct, compiles cleanly For perl, you can test this by executing the script with the "-c" option, which tells perl to make sure it compiles cleanly, but not actually run it. 5) imports the CGI.pm module (use CGI;) If your code just does something really simple, that's all you need, for example it could just contain: #!/usr/bin/perl print "\n\n