CGI/Perl scripts
information
CGI scripts are programs that accomplish
a specific task. If you have one or want to write one, here are the things you
should know of.
Specs &
limitations:
- Our servers fully support perl 5 scripts.
- CGI scripts can be placed in any directory except your root directory.
Your CGI scripts will not run in your root directory! They must be placed
somewhere within your "www" directory. If you would like to create
yourself a "cgi-bin" for organizational purposes, you may, but it
is not required.
Installation
Instructions:
- Changing Parameters: Carefully read the installation instructions
that come with your cgi script. Make any necessary changes to adapt the
script to your server. This is where you might need to know about the server and program paths. Remember that UNIX is case
sensitive, so be sure to spell right.
- Removing Carriage Returns: When edited in a WINDOWS or MACINTOSH
environment, your scripts will end up containing hidden carriage returns
that have to be stripped before your scripts can run. To do this, please
read our "saving with UNIX line feeds"
instructions to learn how to do this.
- Uploading: Upload your script via FTP to a directory on your
site. Remember that scripts can not run in your root directory (the first
directory you see when you use FTP). Instead, put the script(s) in an
existing directory or create a new directory and put them in there.
- Setting Permissions: You need to set the right UNIX permissions
to make your script executable. Go to your File
Manager. Locate your script using the File Manager (use the left frame
to browse through your directories until you see your file in the right
frame). Each file has a set of checkboxes associated with it, grouped under
two headings, "Owner" and "Other". The checkboxes are
used to set permissions for that file. For scripts, you need to change
permissions to chmod 755, which translates to the following:
- Owner: check r, w and x
- Other: check r and x (not w)
After you have checked those
checkboxes, click on "Change Mode".
If you have followed
these instructions, your script should run perfectly. If this is not the case,
please follow our steps for debugging
scripts.
Server
and Program Paths:
Your scripts will most certainly require
you to know one of the following paths, if not all. Here they are:
- Path to Perl interpreter:
When using perl scripts, you need to
change the first line of your script to point to the perl interpreter on the
server. The first line will need to be exactly written as follow:
#!/usr/bin/perl
- Path to Sendmail program:
Some of your scripts might need to
use the sendmail program installed on the server. This usually occurs when
your script is used to send e-mail. In that case, you might need to tell
your program the path to the sendmail program. Please refer to your cgi
script installation instructions to see if this is required. The path to the
sendmail program is:
/usr/lib/sendmail
- Path to Date program:
Some scripts might ask for the path to
the Date program on the server. The path to the sendmail program
is:
/bin/date
- Path to your Domain or Server:
Some scripts might also
ask for the full server path to your site or to files on your site. The full
server path to your site is:
/virtualhosts/domainname/ (i.e.
/virtualhosts/food.com/)
The full server path to files on your site
would then be:
/virtualhosts/domainname/filename
(i.e. /virtualhosts/food.com/pizza.html)
or
/virtualhosts/domainname/directoryname/filename
(i.e.
/virtualhosts/food.com/italian/pizza.html)
"Saving files with
UNIX line feeds" instructions:
Your scripts have to be
saved with UNIX line feeds so that carriage returns are stripped.
- For WINDOWS:
- Download Homesite
- Open your cgi script in Homesite
- Click on the "FILE" menu
- Click on "Save As UNIX LF"
- For MACINTOSH:
- Download BBEdit
Lite
- Open your cgi script in BBEdit
- Click on the "FILE" menu
- Click on "Save As"
- Click on "Options"
- On "Save State", select "DOS"
- Click on "OK", then click on "Save"
Debugging Scripts:
- Use the Perl syntax checker to check if
your script contains any perl syntax errors. The perl checker will not
reveal any paths errors, but only language errors. If there are any, you
need to fix them or re-write the script properly.
- If the script looks fine with the perl syntax checker, check again to
make sure your paths are set correctly.
- Also, check to see if the script is performing a "write"
action. This means that your script is writing data to a file or a set of
files. In these cases, in addition to setting permissions on the script
according to the previous instructions, you also need to also change the
permissions on files that are being written to. Again, use the File Manager
to locate the file(s), but this time, check ALL checkboxes for each file and
click on "Change Mode". For example, guestbook scripts
(guestbook.cgi) usually write guestbook entries to a file called
guestbook.html. Other cgi scripts sometimes write data to a log file.
Therefore, you would check ALL checkboxes for "guestbook.html"
because it is being written to by "guestbook.cgi".
- If your script still doesn't work, please email the support team. When
emailing support, please specify your domain name, username and the URL for
all the necessary and relevant files.