![]() |
Beginning CGI/Perl
1. CGI Basics
“The common gateway interface (CGI) is a standard way for a Web server to pass a Web user's request to an application program and to receive data back to forward to the user.”(http://www.whatis.com/cgi.htm)
In other words, it’s a program that process information sent by the user and sends data back to the browser. This makes CGI a technology that is compatible with most platforms and web browsers with no plug-ins required. Also, since it executes on the server it causes no load on your machine.
Some of the languages used to write CGI programs are: Java, Perl, Python, C/C++, UNIX Shell, etc.
2. CGI vs. JavaScript
|
CGI |
JavaScript |
|
· Runs on the server · Static data · Multiple Languages · Compatible across browsers |
· Runs on the client · Dynamic HTML · JavaScript Only · Sometimes compatible across browsers |
3. Downloading & Installing a CGI from the web
Although there are many sites offering free CGI scripts, it is important that you know that the author of the script has authorized people to use the scripts and that you follow their policies for the use and copyright of the program.
Now we will download and install a calendar CGI script.
Let’s start by going to the following URL.
http://wally.rit.edu/instruction/web/cgi-perl/calendar.tar
This will download a calendar.tar file. The .tar extension means this is a UNIX compressed archive. Proceed to save it on your hard drive in a place where you can easily find it.
Now open an FTP program (i.e. WS_FTP) to transfer the file to your grace account.

The host name will be “grace.rit.edu”. Replace “YourUsername” and the password with you DCE account. Once you establish a connection with the web server you will have a split display. The window on the left is your local drive and the one on the right is the remote server (grace).
You should be able to see a WWW directory on the right hand side. Double click on the folder to access it, this is the directory where your web pages are located. Find the location (on the left) where you saved the “calendar.tar” file. Select binary as the transfer mode and click the arrow that goes from the hard drive to the remote host.
Once done, open a telnet session to grace.rit.edu and login using your DCE account. Then, type “cd www” to get into your web folder. Then to uncompress the calendar.tar file type “tar xpf calendar.tar”. This will create a directory called “calendar” within your www folder.
The permissions are already set by default, but to help you become familiar with file permissions let take a look at them. Type “cd calendar<enter>” to go into the calendar directory and type “ls –al<enter>”. These are the results:

The first column to the left has all of the file permissions. The important file permission to have for CGI scripts is execute(x). In this case the 2 CGI scripts calendar.pl and calendar_admin.pl have the following attribute. RWXR-XR-X. The first 3 letters give the owner of the file read(R), write(W) and execute permissions(x). The second group (people with grace accounts) and the third group (everyone else) have only read and execute access. This means that they can see your script and run your program, but they cannot change it. To set the same permissions on any script you can run the command “chmod 755 FILENAME”.
Now type www.rit.edu/~YOURUSERNAME/calendar in a web browser and you’ll be able to see your files. Read the readme.txt file and try to run the program files.
4. Resources
http://www.hotwired.com/webmonkey/programming/perl_cgi/
Setup program for Perl for Windows, Macintosh, Linux & UNIX.
Lots of resources as well as starting points if you want to write your own Perl scripts