How to use CGI on C.S. Dept. Web Server

Recommended procedures

  1. 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.

  2. 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!

  3. 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.

  4. 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.

  5. 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.

  6. 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


References


This page maintained by:

Edward J. Corbett (edc@cs.unr.edu)



Last modified: Tue Apr 18 12:06:50 PDT 2000