University of Louisville -- dare to be great

Skip Navigation

Data Center Services
Home Page

Web Documentation

IT Home

Accounts

Services

Policies

Major Initiatives

News

Units

Contact

Using CGI at UofL


The main web server at UofL (www.louisville.edu) now offers users three different methods for implementing cgi-bin directories and executing server-side programs:

  1. The system default cgi-bin directory
  2. Userdir cgi-bin directories
  3. SetUID cgi-bins everywhere in the web site

The system default cgi-bin directory

Use of the sytem default cgi-bin directory is limited to applications that are used either by the general web publishing community or for production purposes. General user applications are not stored in the system default cgi-bin. The only applications that users would submit for this directory would be programs that can/should be used by many web publishers at UofL.


Userdir cgi-bin directories

Most cgi applications generally run well out of users' personal cgi-bin directories. All a user needs to do to create a cgi-bin directory is issue the following commands from the unix command prompt:

  • Create a cgi-bin directory.

          mkdir ~/www/cgi-bin

  • Make sure the permissions on the cgi-bin directory are correct.

          chmod 755 ~/www/cgi-bin

  • Create program files in that directory that are executable and readable by the user, group and world, but NOT writeable by anyone other than the user account.
    • If you need to remove the ability of others to write to the file, type:

            chmod -hR go-w ~/www/cgi-bin

    • If you need to make a CGI program file (example: CGI.program.filename) executable and readable by everyone, then type:

            chmod -hR ugo+rx ~/www/cgi-bin/CGI.program.filename

  • Make sure the file is owned by the user's primary group.
    • Type:

            lsuser -a pgrp $USER

      Every thing to the right of the equal sign '=' is the user's primary group

    • Type:

            chgrp groupname filename

    • Double check the file's group ownership by typing:

            ls -l filename.

      In the group column (just to the right of the UserID) there should be the user's primary group.


SetUID cgi-bins everywhere in the web site

As of April 1999, users can also have their own cgi-bins within the document root of the web site. This is a little trickier, but can provide more flexible cgi-bins with simpler URLs. Here's how to make a cgi-bin directory work anywhere within the document root (within the /www/ directory on www.louisville.edu):

  1. Make a directory (example mkdir cgi-bin)
  2. Make sure the directory is world executable but writeable only by the owner (example chmod go-w,g+s,o+x cgi-bin or perhaps chmod go=x,g+s,u=rwx cgi-bin). It is not possible to use WS_FTP Pro to do this correctly. Using WS_FTP Pro to change permissions will result a problem with group ownership (third gotcha below).
  3. Create a .htaccess file in the directory with contents like thus:
         DefaultType application/x-httpd-cgi
         CGIUser USERID
         CGIGroup GROUP
    
    USERID needs to be the userid of the owner of the directory and all files within the directory. GROUP needs to be the group to which the directory and all files will belong.
  4. Place CGI program in this directory.
  5. Make sure that only the owner of the file (you) can write to the directory, subdirectories, and files. (example chmod -hR go-w cgi-bin)

The big gotchas here are:

  • The CGI program has to work.
    • A program that doesn't work, will not work in the CGI environment. Make sure your program works. One way to make sure it works is by running it from the command line (./program.pl)
    • If you are running a perl script, the very first line should include the location of perl. To find out where perl is, type which perl on the command line.
    • Perl scripts must be transfered in ASCII mode. If you tranfer (FTP) them in binary mode, the script will have carriage return (ASCII 13 or ^M) at the end of each line. You will have to transfer the script in ASCII mode to correct this.

  • All files and directories must not be writeable by anyone other than the owner.
    • You can correct this by going to the directory that holds your cgi-bin directory and type chmod -hR go-w cgi-bin

  • All files and directories must belong to the right group.
    • Over time your files may become owned by the wrong group. (See the numbered instructions for an explaination of which group is the right group.) To correct this you can type chgrp -hR GROUP cgi-bin at the Athena command prompt.

If you get the message "500 Internal Server Error", you can check the logs by typing one of the following commands:

  • tail -f /web/httpd/logs/www.louisville.edu.error.log
  • tail -f /web/httpd/logs/suexec_log
  • tail -f /web/httpd/logs/www.louisville.edu.access.log

Please note that the log will entries will scroll quickly.


©2006 University of Louisville. All rights reserved.

U of L Home | U of L A to Z | Contact