Installing and Using Perl Scripts
- Part II
by Outfront Moderator Katherine
Nolan (abbeyvet)
What you need to use Perl scripts
One of the advantages of Perl scripts is that they
need very little in the way of specialized features on
your server. Just about everyone on a Unix type server
will be able to use them, and many scripts (including
our sample script) will also run happily on NT servers.
However a quick review of what is required before you
begin will avoid problems later.
What you need on your computer
1. An unzipping utility - eg WinZip
Most cgi scripts in fact consist of a number of interlinked scripts and configuration files and often HTML and text files also. They are usually made available for download as a zip file and you will need a way of unzipping them.
You can download an evaluation copy of WinZip here:
http://www.winzip.com/ddchomea.htm
A single user license costs $29
2. An FTP client - eg WS_FTP
Files that are part of a cgi script should never be published from within FP, they need to be uploaded using FTP. To do this you will require an FTP client.
You can download an evaluation copy of WS_FTP here: http://www.ipswitch.com/cgi/download_eval.pl?product=WS-0000
There is a shareware version available free to educational users, government employees (U.S. local, state, federal and military) or to non-business home users only.
A single user license for the pro version costs $39.95
During this tutorial we will refer to WS_FTP but if you already have another FTP client the procedures will be pretty much the same. If you have not used an FTP client before please take some time this week to have a look around at it and become familiar with its basic interface. There are good introductory tutorials about installing and using WS_FTP here:
http://www.ftpplanet.com/tutorial/
3. A text Editor
Notepad will do fine or you can use whatever text editor is your favorite. Scripts should not be opened and altered in FrontPage.
What you need to know about your server
CGI/Perl scripts run on most Unix servers, though the one we have chosen is suitable for use on NT servers also. However these instructions refer to Unix type servers.
You need to find out the following about your server:
1. Can you run Perl Scripts?
Most hosts allow scripts to be run, a few do not. You should be able to find this information on your hosts support pages.
2. Where should your scripts be uploaded?
Most hosts require that scripts be placed in a specific directory, usually called either cgi-bin or cgi-local. This directory will probably have been created for you when your site was set up initially, you can FTP in to your site to see if it is there and what it is called or ask your host if you are unsure.
Please note: This directory will not exist in your FP web on your own computer and you do
NOT need to create it.
3. What is the Path to Perl on your sever?
In order to function your script will need to know where to find Perl, the set of code instructions that allow it to function.
The first line of all scripts is something like this:
#!/usr/bin/perl
or
#!/usr/local/bin/perl
This line is vital and it tells the script where to find Perl on the server. Your host support pages will probably tell you which is appropriate on your server, if not, contact them and ask them what the 'path to Perl' is.
4. Your Server File paths
There is often confusion between file paths and URLs so we will deal with that here in some detail and give you a chance to get familiar with the concept. One of the biggest causes of problems when uploading CGI scripts is getting the server paths wrong, so if this is new to you read and reread this section until it starts to make some sense to you!
We are all familiar with the structure of URLs, for example:
http://www.thesite.com/directory/subdirectory/file.htm
A browser will use this information to find the page file.htm and display it.
However the server sees things rather differently in its internal functioning and finds files using the server path. The server path consists of two parts:
a. The path to the root directory of your site on the server.
The exact path will vary from server to server but will look something like this:
/usr/www/yoursite/
Again the exact paths may be available on your hosts support pages or you can email them and ask. Another way to find out is to FTP in to your site. Once your site opens in the FTP client you will see the server path displayed in the location window.
b. The path to the actual file or directory within your site.
This will be the same as whatever comes after your base URL - so using the example URL above the full path would be something like:
/usr/www/yoursite/directory/subdirectory/file.htm
It is very important to understand the difference between URLs and paths. When we come to configure the script we will need to use server file paths to tell it where to find files on your server.
Please note that forward slashes are used, not back slashes as in the file system on your computer.
5. Acceptable file extensions
Perl files use the extensions .pl or .cgi, often interchangeably.
While most servers allow either to be used, some insist on one or the other. Again you need to know if this is the case on yours.
Often the extensions are interchangeable, so if a script is called script.cgi you can rename it script.pl and no harm done. However you will need to record this somewhere during the configuration of the script (next week!) so find out about it now.
I know that much of this will seem like double Dutch to those of you who have not worked with scripts before but please do not panic, as we work through installing our script over the next couple of weeks it will all become clear. In the meantime you might like to copy this short email (or whatever parts of it are appropriate) to your host and get all the information you need in one place.
<---Begin email----->
Please could you give me the following information about my site: http://www.yoursite.com.
1. Am I allowed to run Perl Scripts?
2. What is the name of the directory in which they should be installed?
3. What is the path to Perl?
4. What is the file path to my root directory?
5. What file extensions are allowed: .pl or .cgi or both?
<---End email----->
In the next part of this tutorial we will look at how to find, select and evaluate scripts, we will download one and then
configure it for and upload it to your server.
<< Part I: Introduction and
Preparation
>> Part III: Choosing and Evaluating Scripts