How to use CGI on C.S. Dept. Web Server
Recommended procedures
- Create a cgi-bin directory in your public_html directory
- For example, mkdir ~username/public_html/cgi-bin.
- Programs will be accessed as http://www.cs.unr.edu/~username/cgi-bin/prog.cgi.
- Write some HTML-producing code in a scripting language (Perl recommended)
- First line must be "Content-type: text/html", followed by a blank line. IMPORTANT!
- Make sure file ends in ".cgi".
- So that the server knows to transmit it as a CGI program.
- Otherwise, the source code will be displayed as text.
- You can use links, so that the same file has 2 names, and you can do both with it.
- E.g., ln prog.pl prog.cgi.
- Set permissions correctly.
- Set permissions on your cgi-bin directory to 705 or 701, depending on whether you want others to be able to read your directory.
- Do not set permissions to 777! It will not work.
- Make sure all directories above have at least world-executable permissions, e.g. at least 701.
- Set permissions on your .cgi files to 705 or 701, depending on whether you want others to be able to read your source code.
- Verify that you have the correct ownership on files and directories, both user and group ownership.
- ls -lg , to check.
- Test your program.
- Run it at the command line first to make sure it gives the desired output, and debug it.
- Try it in your browser.
- Be careful out there...
- CGI programs that you write can be run by others with your permissions.
- Be very wary of writing programs that can delete or overwrite files.
Simple Examples
Perl Bourne Shell C program description hello.pl.cgi - source code
hello_sh.cgi - source code
hello.c.cgi - source code
using "print" statements to write HTML code.
hello2.pl.cgi - source code
hello2_sh.cgi - source code
hello2.c.cgi - source code
doing a pass through of HTML code.
date.pl.cgi - source code
date_sh.cgi - source code
date.c.cgi - source code
captures output from UNIX "date" command and writes HTML code.
References
- CGI Programming on the World Wide Web
- CGI Programming with Perl, 2nd Edition
- Web Client Programming with Perl
- Learning Perl, 2nd Edition
- Programming Perl, 2nd Edition
- HTML: The Definitive Guide, 3rd Edition
- perl.org
- perl.com
This page maintained by:Edward J. Corbett (edc@cs.unr.edu)
Last modified: Tue Apr 18 12:06:50 PDT 2000