CGI Configuration

CGI scripts are a way for documents to be generated on the fly. You should first read this brief introduction to CGI to learn what it is and why you would want to use it.

There are two main mechanisms to tell NCSA HTTPd where your scripts are. Each has its pluses and its minuses.


ScriptAlias Directories

The first approach is based on the
Server Resource Map directive ScriptAlias. With this directive, you specify to the server that you want to designate a directory (or directories) as script-only: that is, any time the server tries to retrieve a file from these directories it will execute the file instead of reading it.

The usual setup is to have the following line in srm.conf:

ScriptAlias /cgi-bin/ cgi-bin/
This will make any request to the server which begins with /cgi-bin/ be fulfilled by executing the corresponding program in ServerRoot/cgi-bin/.

You may have more than one ScriptAlias directive in srm.conf to designate different directories as CGI.

The advantages of this setup are ease of administration, centralization, and slight speed advantage. Many system managers don't want things as dangerous as scripts anywhere in the filesystem. The disadvantage is that anyone wishing to create scripts must either have their own entry in srm.conf or must have write access to a ScriptAlias'd directory.


CGI Anywhere

As of NCSA HTTPd 1.2, you can have the server execute CGI scripts anywhere. This is broken in different ways up until version 1.5, which should actually work completely, allowing full usage of CGI scripts in any location in the document tree, including if you use the AddType in .htaccess files.

NCSA HTTPd allows you to do this by by specifying a "magic" MIME type for files which tells the server to execute them instead of sending them. To accomplish this, use the AddType directive in either the Server Resource Map or in a per-directory access control file.

For instance, to make all files ending in .cgi scripts, use the following directive:

AddType application/x-httpd-cgi .cgi
Alternatively, you could add .sh and .pl after .cgi to allow automatic execution of shell scripts and PERL scripts. Note that you have to have Options ExecCGI activated in the directory you create scripts.

The advantage of this setup is that scripts may be absolutely anywhere. The disadvantage is that scripts may be absolutely anywhere (especially places you don't want them to be like users' home directories).


[Back] Return to the tutorial index
NCSA HTTPd Development Team / httpd@ncsa.uiuc.edu / 9-27-95