You can enable CGI scripts to be placed in any directory by specifying some CGI directives in a directory container within the httpd.conf or an .htaccess file. This allows CGI execution in the directory specified:
Options ExecCGI (other options…)
Limiting CGI Access
If you do not have Options ExecCGI or a ScriptAlias directive, the execution of CGI programs will be denied.
You can limit CGI access to only programs that end with a specific extension:
SetHandler: AddHandler cgi-script .cgi
(limits CGI execution to programs that only end in .cgi)
http://iti.rutgers.edu/~chrisjur/cgi-bin/test.cgi - CGI script written in Perl, simply outputs current time and the end-user’s browser type (source at /home/chrisjur/public_html/cgi-bin/test.cgi)
http://iti.rutgers.edu/~chrisjur/cgi-bin/shell.cgi - Written as a shell script in, prints current date/time and lists files in its directories (source at /home/chrisjur/public_html/cgi-bin/shell.cgi)
More CGI Examples…
http://iti.rutgers.edu/~chrisjur/feedback.html - More traditional example of what CGI is used for. An HTML form posts to a CGI script written in Perl (/home/chrisjur/public_html/cgi-bin/feedback.cgi) which emails form contents to a recipient and performs some validation logic.
Exercise: Enabling CGI
Enable CGI via the ScriptAlias directive in your httpd.conf. Specify a cgi-bin directory to place all your CGI scripts.
Copy /home/chrisjur/test.cgi script to your cgi-bin directory. Make the test.cgi script executeable (chmod a+x test.cgi)
Access the script via http://iti.rutgers.edu:YourPort/cgi-bin/test.cgi