Title: Learn CGI
Author: Eddie

Can we put our CGI programs(scripts) to any directory to make it run? Obviously the answer is "no". Before you write your own CGI programs, you'd better make sure whether you have permission to execute CGI scripts. Otherwise you are just wasting your time.

Most often we see people place their CGI program in server's cgi-bin directory. When you want to use your own CGI programs, you must first ask the web master to put your CGI programs in the cgi-bin directory. But this is not the only way.

Usually, the web server controls access to directories or files through Access Configuration file. Different server have different way to implement it. For example, for Apache webserver and NCSA httpd server, there are two methods for controlling access to directories:

Global Access Configuration File A document in server's conf directory, by default is access.conf, which controls access to any directory in your tree. For example, we can give the cgi-bin directory permission to execuate CGI program, of course we can give other directory the same permission in server's home directory. But this is not recommended for security reason. This is why cgi-bin is the most common way. This can be only defined by the web master or system administrater.

Per-directory Access Configuration File The default file is .htaccess, which control access to directory and its sub-directory. This can be define by the common user. But this can be restricted or completely forbidden by the Global ACF.

So Now we can see that there's two ways to place your CGI programs: Ask your web master to put your CGI scripts in the server's cgi-bin or other directory with CGI execuation permission.

If not forbidden by the global ACF, you can add this statement to your .htaccess file( which should locate at your own web root directory):

AddType application/x-httpd-cgi .cgi
AddType application/x-httpd-cgi .pl

This tells the server that all files have the .cgi and .pl extension are CGI programs. Of course you need to change all your CGI programs with .cgi or .pl extension.