Most of us do not run their own Web servers on their own PCs. Instead our pages are hosted on big Unix of Linux boxes. Administrators can not let users run their own CGI scripts in the system directories for obvious security reasons. For the same reasons CGI scripts should not be run from the same locations where the regular web pages come from. Therefore they are disabled by default. However, there is a way to localy enable CGI capabilities for a particular directory. The following description applies to Apache Web server and other servers that use .htaccess configuration files.
If you want to enable a directory and its subdirectories for CGI, create the following .htaccess file:
Options +ExecCGI addType application/x-httpd-cgi .cgi .plThese contents may be combined with other configuration features such as restricted access to a part of your Web site. If the system administrator really do not want you to run CGI scripts she or he can disable the use of .htaccess files for all users. .htaccess file must be set to be readable by everybody.
Now place your script in the same folder where .htaccess file is. Make sure that the scipt has extension .cgi or .pl. The latter is commonly used for programs written in PERL - a popular language for writing CGI scripts. In case you wrote your script in C or C++ you must compile it using a compiler for the particular operating system. For example a program compiled on Windows will not run directly on Unix or Linux. You have to compile the source code using a complier for Unix, Linux, or other operating system accordingly.
After the program is transfered to the Web server it needs to be marked as executable. Typically files are marked and read-write only by default and cannot be run as programs. You can do it by typing in consloe window the following command:
chmod a+rx program.plwhere program.pl is the name of your program.
You can test a sample script in PERL and look at its see its source code. If you want to copy the script to your Web site you need to modify content of the very first line so that it points to the location of PERL on your Web server.
There are some security issues in case your program needs to write to a file - you need to set permission for other people (such as Web server daemon) to allow modification of that file or files in your directory. Use chmod command to enable proper access to some of your files. See another step by step example that shows how to set up such program so that it can run.
Enjoy!