Setting up CGI in NCSA httpd

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.


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 desingnate different directories as CGI.

The advantage of this setup is ease of administration, and centralization. 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 ScriptAliased directory.

CGI as files

NCSA httpd 1.2 allows you to create CGI scripts anywhere, 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).

Return to the tutorial index