Configuring Apache to permit CGI In order to get your CGI programs to work properly, you'll need to have Apache configured to permit CGI execution. There are several ways to do this. ScriptAlias The ScriptAlias
directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.
The ScriptAlias directive looks like: ScriptAlias /cgi-bin/ /usr/local/apache/cgi-bin/
The example shown is from your default httpd.conf
configuration file, if you installed Apache in the default location. The ScriptAlias
directive is much like the Alias
directive, which defines a URL prefix that is to mapped to a particular directory. Alias
and ScriptAlias are usually used for directories that are outside of the DocumentRoot directory. The difference between Alias
and ScriptAlias
is that ScriptAlias
has the added meaning that everything under that URL prefix will be considered a CGI program. So, the example above tells Apache that any request for a resource beginning with /cgi-bin/ should be served from the directory
/usr/local/apache/cgi-bin/, and should be treated as a CGI program.For example, if the URL
http://dev.rcbowen.com/cgi-bin/test.pl is requested, Apache will attempt to execute the file
/usr/local/apache/cgi-bin/test.pl
and return the output. Of course, the file will have to exist, and be executable, and return output in a particular way, or Apache will return an error message. |