Once you've read the section on this guide about Apache, and got your server running, create a directory named cgi-bin in the directory from which you run your server. This is the directory that your server is configured to run CGI scripts from. Once this folder is created, you can put programs in it that can be executed by your web server.
Before we go any further, you must be very careful about what programs you allow your server to execute. The programs found in your cgi-bin directory will be run with the same authority as the user that started the web server (in this case you). If your CGI program does something like rm -r $HOME/* you may find yourself in big trouble! There are many other security concerns with running CGI programs that will be covered in class.
CGI programs are commonly written in the Perl programming language but by no means have to be written in Perl. You can write a CGI program in any language that you choose.
With that said, lets try running your first CGI program. First make sure your web server is running and that you've created the cgi-bin directory in the appropriate location. Next, download the CGI.tar file and unpack its contents your cgi-bin directory. The archive contains 3 CGI Hello World CGI implementations in different programing languages, and a README file that explains how to compile and install the scripts. This file also includes a helpful troubleshooting section. Please read and follow all instruction in the README file before you continue to the next step.
To execute the CGI scripts point your browser to http://localhost:your_port_number/cgi-bin/cgi_script_name.
You should see something like:
Running CGI on your Home PC
If are running Apache on you home PC, be mindful that by default Apache has the option to run CGI scripts disabled. To enable CGIs, edit the file httpd.conf, which is located in the conf directory and add the flag ExecCGI to the Options declaration. If you are running Perl-based CGIs make sure that Perl is actually installed in your system, and that the first entry in the Perl script points to the appropriate location where Perl is installed in your system.Online CGI and Perl Resources
- CGI 1.1/1.2 RFC Project - http://cgi-spec.golux.com/
- W3C CGI page - http://www.w3.org/CGI/
- Larry Wall's Perl page - http://www.wall.org/~larry/perl.html
- Comprehensive Perl Archive Network (CPAN) http://www.cpan.org/
- O'Reilly "Camel book" - http://www.oreilly.com/catalog/pperl3/
