CGI on bama
Please note: In order to set up most CGIs, you should have an interactive shell on your bama account. More information is available.
Shared CGIs
bama contains some CGIs already set up for use. These are located in
/usr/local/apache2/cgi-bin. Some CGIs provided include FormMail
and a counter. You can call them with the
paths
/cgi-bin/script_name
or
http://bama.ua.edu/cgi-bin/script_name
Personal CGIs
If you would like to run personal CGIs, you must come to the HelpDesk and sign a statement of responsibility. Your account name will be added to the list of users who are allowed to use personal CGIs. Once that is done, you must put all of your CGIs in a directory called cgi-bin located under your home directory (not under public_html). All scripts should have the extensions .cgi or .pl (for perl).
Calls to your personal CGI scripts should be made in the form
/cgi-bin/cgiwrap/~account/script_name
or
http://bama.ua.edu/cgi-bin/cgiwrap/~account/script_name
You can create subdirectories under cgi-bin if you would like; calls to those scripts would include the subdirectory name(s) after ~account/ .
Scripts run this way will run as your account name instead of the server's name. So, all of your script files can have the "group" and "other" permissions turned off, resulting in more security for you.
If you would like to use server-side includes with your personal
CGI scripts, you should note that the "exec cgi" method
does not work through the wrapper. An SSI call to a personal
CGI script should be in the form
<!--#include virtual="/cgi-bin/cgiwrap/~account/script_name" -->
And remember that a page with server-side includes should end with
the .shtml suffix.
Troubleshooting
If you are running a CGI script and it isn't working, you may want to check the error log. The best way to do this is to type the following command on bama as quickly as you can after you run your script:
tail /usr/local/apache2/logs/error_log
Also, if your script passes back the line "Content type: text/html" as the first thing (followed by a blank line), in some cases script error messages will print out through the browser.
Why does my script work OK when I execute it directly, but not on the Web?
If you wrote your CGI program as a script then you should add a line
at the top which points to the shell you used. This would be
#!/bin/sh
or
#!/usr/local/bin/perl
or something similar. Remember that when you execute the script directly
conditions are different from when it is executed by the Web server.
The Web server will execute the script as you but not as though you
logged in. You need to consider permission, environment, and the shell
language to get it all to work.
Another problem common to CGI programming is omitting a required
first line. The first line your script should send back is
Content-type: text/html
then there should be a blank line.
Why doesn't the Perl script I got off the Web work?
First, check the top line of the script. It will point to the Perl interpreter. This may have the wrong directory as a default. Ours is located at /usr/local/bin/perl.
Next, check how you are calling the script. The most common problem with calling scripts is a path error.
Why doesn't the script I wrote on my PC work when I move it to bama? I got it straight from a book example.
Files which are written on a PC have a carriage return character (^M) at the end of every line. The Unix shells (and Perl) do not like this. Either remove them (using a editor which shows you where they are, such as "vi") or use the utility "dos2unix":
dos2unix dos-like-file unix-like-file
where dos-like-file is the file you transfered from your PC and unix-like-file is the name you want it to have on the Unix machine. Do not pick the same name for both. You can always rename your Unix file, if you need to.

