?
In this article you will learn how to configure Apache Server sothat will permit CGI execution. First before you start with CGI youneed to have Apache configured so it will run CGI programs to workproperly. Above you will find some samples on how to configure ApacheServer.
ScriptAlias
The ScriptAliasdirective tells Apache that a particular directory is set aside for CGIprograms. Apache will assume that every file in this directory is a CGIprogram, and will attempt to execute it, when that particular resourceis requested by a client.
The ScriptAlias directive looks like:
"#ff0000">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 ScriptAliashas the added meaning that everything under that URL prefix will beconsidered a CGI program. So, the example above tells Apache that anyrequest 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://www.example.com/cgi-bin/test.pl is requested, Apache will attempt to execute the file /usr/local/apache/cgi-bin/test.pland return the output. Of course, the file will have to exist, and beexecutable, and return output in a particular way, or Apache willreturn an error message.
CGI outside of ScriptAlias directories
CGI programs are often restricted to ScriptAlias'eddirectories for security reasons. In this way, administrators cantightly control who is allowed to use CGI programs. However, if theproper security precautions are taken, there is no reason why CGIprograms cannot be run from arbitrary directories. For example, you maywish to let users have web content in their home directories with the UserDir directive. If they want to have their own CGI programs, but don't have access to the main cgi-bin directory, they will need to be able to run CGI programs elsewhere.
Explicitly using Options to permit CGI execution
You could explicitly use the Options directive, inside your main server configuration file, to specify that CGI execution was permitted in a particular directory:
"#ff0000"><Directory /usr/local/apache/htdocs/somedir>
Options +ExecCGI
</Directory>
Theabove directive tells Apache to permit the execution of CGI files. Youwill also need to tell the server what files are CGI files. Thefollowing AddHandler directive tells the server to treat all files with the cgi or pl extension as CGI programs:
"#ff0000">AddHandler cgi-script cgi p
.htaccess files
A .htaccessfile is a way to set configuration directives on a per-directory basis.When Apache serves a resource, it looks in the directory from which itis serving a file for a file called .htaccess, and, if it finds it, it will apply directives found therein. .htaccess files can be permitted with the AllowOverridedirective, which specifies what types of directives can appear in thesefiles, or if they are not allowed at all. To permit the directive wewill need for this purpose, the following configuration will be neededin your main server configuration:
"#ff0000">AllowOverride Options
Source of the Article