|
If you get the jitters just thinking about installing a
CGI program, this article is for you.
The best way to get over the jitters, that I know of,
is to go ahead and install one. This article has a
four-line script you can use to practice with.
Two things to remember when working with scripts
-
When editing Perl CGI scripts, always use a plain
text word processor. NotePad (PC) or BBEdit (Mac) are
your friends.
-
When uploading Perl CGI scripts, always do so with
an FTP program and transfer the file in plain text
mode (as opposed to binary mode).
Using methods other than FTP, such as FrontPage or
even some so-called "upload control panels"
can break scripts. If you don't have an FTP program, http://tucows.com/
lists several.
"FTP" means "File Transfer
Protocol." Use the tool for the job.
Of course, you'll need to have a directory on your
server that is allowed to run Perl CGI programs. These
directories are often referred to as the cgi-bin, and
sometimes the directories even have that name. Other
common names for the cgi-bin are "cgi-local" and
"cgi". If unsure, ask your hosting company.
If your hosting company does not allow you to run CGI
scripts, you might consider opening an account with one
who does. Free hosting like that available from Hypermart
at http://www.hypermart.net/t/registration/packageinfo
is an option, especially when getting started and wanting
experience to help make future hosting decisions.
Time to Practise!
Here is the 4-line script you can practice with
#!/usr/bin/perl
$Message = "<h1>Congratulations, my friend!</h1>";
print "Content-type: text/html\n\n";
print "<html><body>$Message</body></html>";
Copy and paste (or type) the above 4 lines into NotePad
or BBEdit. Save the file as practice.cgi (or something.cgi
if you already have a file named practice.cgi on your hard
drive or on your server).
Verify that the first line of the script is correct. It
must start with the characters #! and be followed with the
location of the Perl interpreter on the server. Your
hosting company can tell you that location. The correct
line is probably #!/usr/bin/perl or #!/usr/local/bin/perl
Use your FTP program to upload practice.cgi onto your
cgi-bin.
Once uploaded to your server, the script needs
permission to run. Some servers are configured to
automatically set the correct permissions when scripts are
uploaded. If yours doesn't, set permissions to global
execute. That is
user - read/write/execute
group - read/execute
other - read/execute
which corresponds to permissions number 755. Your FTP
program is the tool to use for setting permissions.
Different programs have different methods of doing so, but
most have either checkboxes where you can select according
to the list above or a place where you can type in the
permissions number. If your FTP program requires a 4-digit
number, use 0755.
For a more extensive discussion of
"permissions", see the "Unix/Linux File
Permissions" article linked from http://willmaster.com/possibilities/archives/
To run practice.cgi, type its URL into your browser,
something like this
http://yourdomain.com/cgi-bin/practice.cgi
If everything works as it should, you should see
Congratulations, my friend!
in your browser window.
If it doesn't work, try the installation process again;
start from the beginning with a clean slate. The error
might have been something overlooked or a simple mistake.
If it still doesn't work try one of these resources
The FAQ at http://mastercgi.com/faq/
lists the common reasons for installations to fail.
The "How to Install CGI Programs" ebook
written by your author (published by Intellectua of http://intellectua.com/
) and obtainable from http://willmaster.com/a/15/pl.pl?pie1
has lots of additional information.
Even if things go well with practice.cgi, consider
buying "How to Install CGI Programs" ($12.95).
It is a great tutorial and could be indispensable for
future installations.
Now that you've installed practice.cgi, you might try
your hand at editing it. Change the message to something
with your name in it, for example. Then do another change,
like adding an HTML horizontal rule tag <hr> into
the last line of the script, before or after the $Message
variable.
To increase your confidence, install some of the
scripts from the Master Series at http://willmaster.com/master/
Master Feedback and Master Recommend, both free, are
fairly easy to install and provide basic functionality
every web site should have.
The more you work with scripts, the more confident you
will become.
And when you're filled to the brim with confidence and
want to tackle writing your own script, read the 4-part
"Writing Your Own Form Handling Scripts" series
linked from http://willmaster.com/possibilities/archives/
That should keep you busy until next week :)
By: Will Bontrager
Copyright 2002 Bontrager Connection, LLC
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com
|