|
San Diego State University |
Last updated: 9/12/00 |
|
Guide To CGI on ROHAN |
Page 3/3 |
There are quite a few things that can potentially go wrong when setting up a CGI script,
since doing so requires making several different things work at once: HTML, paths,
permissions, variables, and the Perl itself. Choose an option below that best describes
your situation:
My Script Won't Work From the Web
[ top
| table of contents ]
Hint: Try running your script from the command line before you troubleshoot from the web-side. It
is possible that the script is not being executed correctly on the server. Once you have
ruled this out, try the following tips to troubleshoot your HTML code.
Since perl scripts are executed on ROHAN before they are served to the web browser, many
problems need to be diagnosed from the server rather than from the web. To test your script
from the server, you need to telnet to ROHAN. On a Windows PC, go to the Start menu and choose
Run, then type telnet rohan.sdsu.edu in the box and hit enter. From an Xterm or another
UNIX, just type telnet rohan.sdsu.edu from your prompt. Log in with your username and
password, then change to your public_html directory.
Where Can I Find Additional Resources?
[ top
| table of contents ]
First of all, are you linking to the script directly, as in
<a href="file.cgi">click</a>, or are you calling it from
within another HTML file, as in <!--#exec cgi="file.cgi"-->?
If you are linking to it directly, first make absolutely sure that you spelled
the filename right and that the path to the file exists. Try going to the
directory in which your CGI is stored, and typing pwd at the command
prompt. This will give you the full path to your CGI script.
If the link seems to work but the script itself is not producing the right
results or is giving you an error, see the list of
common error codes below.
If you are calling the script from within an HTML document, first make sure
that the HTML has a .shtml extension. This is important because it
tells the server to parse the HTML before serving it to the web browser.
Remember that you must use the path to the script relative to where the HTML is
located. If the script is in the same directory as the HTML, then
<!--#exec cgi="file.cgi"--> is sufficient. However, if file.cgi
is located in another directory, say the parent directory of where the HTML is,
you need to specify that in the exec tag:
<!--#exec cgi="../file.cgi"-->.
My Script Won't Work From the rohan% Prompt
[ top
| table of contents ]
To run a Perl script from the rohan% prompt, type perl file
where file is the name of or path to your script. If the script is working, you will
likely get some output beginning with the line Content-Type: text/html\n\n, or at
least containing some familiar HTML tags. It is possible that a script made for the web would
output an error message when run from the rohan% prompt, so try running it from the web as well.
Here are a list of some Perl error messages and what they mean:
You mistyped the filename or path, or the file does not exist. Run an ls command from
the rohan% prompt to make
sure the CGI file is in your current directory. Also remember that UNIX is case-sensitive, so
File is different than file.
syntax error at file line X, near Y)
You probably forgot to add a semicolon after a line somewhere around line X. Most Perl
statements require a semicolon to separate different commands.
You probably forgot to include a $ symbol before the variable. In Perl, scalar variables need
to be referred to as $variable. The statement $variable = foo; is correct, but
variable = foo; is not.
UNIX and DOS-based (or Windows-based) computers use slightly different formats for plaintext
files. At the end of each line, where you would hit Return when typing a paper, there is a
special character called a carriage return or a linefeed. This character differs on the
different operating systems. If you create a Perl script on a Windows-based computer
(or download it from someone who has,) and attempt to run it under UNIX, it will sometimes
cause Perl to fail because it cannot recognize the carriage return character at the end of the first line.
If you get other error output, try emailing the author of the script and describing the problem and the output you received. You may also want to read the Perl documentation with man perl .
Common HTTP Error Codes
[ top
| table of contents ]
403 Access Denied
This error indicates that you do not have the correct permissions set on the file you are
trying to access. Make sure that your HTML files are readable by everyone (chmod 644
file.html), and that CGI files and directories are both readable and executable by
everyone (chmod 755 filename).
404 File Not Found
This error indicates that the path to an HTML or CGI file is incorrect. Double-check your links.
Remember that internal and external paths are different, and that UNIX is case-sensitive so that "WebPage" is different than "webpage".
500 Internal Server Error
You will get a 500 error for the following reasons:
Document contains no data
This error code means that the page your browser is trying to retrieve contains no usable data.
Usually this is caused by a CGI script failing to run and thus producing no output.
Another possibility is that the server is responding too slowly and the connection has
timed out before any data could be sent.
[an error occurred while processing this directive]
This is an error produced when an SSI call has a problem. For our purposes, it usually means
that you mistyped the location of your CGI script within the
<!--#exec cgi="../file.cgi"--> tag, or made some other typo.
Some Sample CGI Scripts
[ top
| table of contents ]
© 2000