|
|
Library
> Articles >
Web Design
> 006
|
|
|
|
An
Introduction to CGI
Contributor:
Mike de Sousa, Director, AbleStable®

Here's
your plain and simple introduction into the world
of the Common Gateway Interface (CGI or CGIs), an
immensely useful computer protocol that provides
the opportunity to introduce interactivity and increased
functionality into web sites without programming
or coding knowledge.
Common
sources of information, scripts and programs
The
intention of this article is to introduce CGI for
those who have little or no knowledge of it. In
this article we'll describe what CGI can do, and
run through some fundamentals to upload a CGI program
effectively. For those wishing to develop CGI scripts
of their own or to gain a greater understanding
of CGI in general two great places to visit are:
http://www.cgi-resources.com/
http://scriptsearch.internet.com/
If you're using a PC to upload files and set permissions
for CGI scripts we'd recommend you use the FTP program
Smart FTP available for free from http://www.smartftp.com.
The journey from the client
to the server and back
Before
we begin our journey it's best we clarify a few
principles to the uninitiated. Any script can be
called a CGI script as long as it's installed on
the server end. Anyone wishing to utilise the advantages
of CGI must remember CGI is a two way exchange of
information between the 'client-side' and the 'server-side'.
The client-side in this case is the general user
viewing a web page on a web browser like Microsoft's
Internet Explorer. The server-side is the host computer
that delivers the web pages from a remote location.
It is not possible to simply cut and paste a CGI
script into a web page and hope that it will work
on a web site. CGI requires that the host server
is CGI enabled. The script processes the requests
made of it, then delivers the results of the request
in some meaningful form back to the client.
Remote
control
The CGI requests are directed to a specific folder
on the host server where the main CGI functionality
resides. Think of the client's web page (those available
to browse) as carrying instructions and commands
which, when sent, are received, interpreted and
actioned by an automated program.
CGI scripts and programs can be written in any computer
language. The most popular languages used for the
creation of CGI scripts and programs are:
Perl: the most
common CGI scripting language
C+: a common
PC based computer programming language
AppleScript:
a Macintosh based scripting language.
Unix Shell:
CGI scripts written in sh, ksh, csh, or other UNIX
shell.
Visual Basic:
a Microsoft Windows scripting language
What
CGI can do
CGI
programs can automatically add a great amount of
information on web pages. CGI scripts and programs
are used for many tasks, a few of the most common
are:
the creation
of dynamic documents like search engines
the implementation
of a site guestbook or bulletin board
the ability
to display the current date and time
the ability
to update personal information
the ability
to submit forms
the ability
to rotate image and text content
CGI
requirements
The first task of anyone wanting to use CGI is to
ensure their host server:
supports CGI
is running the
appropriate operating system (usually UNIX or Linux)
has the appropriate
CGI language installed (usually Perl)
has sendmail,
qmail or equivalent depending on the CGI to be used
supports the
appropriate Perl or equivalent module
You must also have and be able to use an FTP program
for uploading files, creating directories, and changing
permissions (if your hosting company provides a
Control Panel for this purpose, the maximum file
size that can be uploaded is often around 32k. Some
CGI files may be larger so check first).
There are many FTP programs for PC and Mac that
allow the directory and file permissions to be changes
(referred to as CHMOD), and a good selection is
available for download at http://www.download.com/
Installing
a CGI program
The installation of a CGI program will depend on
the care and attention the programmer has given
to the installation process. The best programs will
all-but self-install and contain generous help,
information, documentation, and administration areas.
But beware, many CGI programs are sadly lacking
in this regard. Do your homework before buying a
CGI program and know what's on offer and what isn't.
You'll require two tools in addition to the host
server to assist with the full implementation of
CGI:
an FTP program
like Smart FTP available for free from http://www.smartftp.com
a basic
text editor (Windows users can use Notepad, MacOS
users can try Mactext or BBEdit, and UNIX users
can try vi or emacs).
The FTP (File Transfer Protocol) program is an application
to transfer files from a local folder to your server).
The text editor allows you to configure the CGI
program which is a text file ending with .pl (Perl)
or .cgi.
The
path to nowhere
CGI programs must be placed in a directory allowed
to run CGI programs, probably a directory called
'cgi-bin' or similar. Be careful however as there
is no agreed protocol on the naming of files and
you may find your server's path to the CGI folder
is different. Your host should provide you with
this information. You are best advised to create
a special folder for each CGI program within your
'cgi-bin' to keep your CGI scripts organised.
Establish the path to the Perl compiler on your
web host (or other compiler depending on the language
being used) by asking your host.
Upload the CGI program files into the directory
you decided upon as ASCII/plain text (not binary)
and set the file permissions (this process is often
referred to as 'chmod files').
In addition you may be required to enter your server's
mail program and CGI Bin. The following addresses
are provided as a guide, however you must check
with your host to ensure your server details are
correctly entered (there are no rules here). For
sendmail the path may be: /usr/lib/sendmail, and
for the CGI-BIN the path may be: /usr/local/etc/httpd/sites/mysite.com/cgi-bin.
Setting permissions
When you first upload your CGI files you'll need
to set your 'permissions'. Be aware many common
web site generation programs like Macromedia Dreamweaver
do not surprisingly support this FTP functionality.
You may require a separate FTP like Smart FTP from
http://www.smartftp.com
which we've found to be the best by far.
Permission numbers translated into attributes (some
FTP programs use the term 'Other' or 'Global' instead
of the term 'World' as used below):
0755 Global read/execute
permission
Owner: read-write-execute
Group: read-execute
World: read-execute
0766 Global read/write
permission
(If your server won't write to directories with
0766, use 0777):
Owner: read-write-execute
Group: read-write
World: read-write
0777 Global read/write/execute
permission
(Try 0766 first):
Owner: read-write-execute
Group: read-write-execute
World: read-write-execute
Testing
Once you have successfully uploaded your CGI program
onto your server you must test it as there are many
reasons why a CGI program might not to work. Follow
the FAQ checklist below:
is your server
CGI enabled?
has the CGI
script been uploaded into the correct server folder?
is your CGI
file path on the web page correctly configured?
is there a
problem with the CGI source code?
have you ensured
the correct permissions have been set on the remote
server?
have you tested
your web page in a variety of browsers and operating
systems?
Conclusion
To someone who has never installed a CGI program
before it may at first seem an intimidating and
complex task to pull off but don't be put off. As
we've mentioned, there are great CGI programs out
there that will auto-install, and installing one
yourself is often only a matter of entering file
paths correctly. Once you've CGI enabled your web
site you'll wonder how you ever lived without it
as it transforms your site into an interactive and
dynamic web destination.
|
|
|
|
| |
|
|
|
 |
| |
| Authors
background |
Mike
de Sousa is the Director of AbleStable®.
Mike has been commissioned as an artist, music
composer, photographer, print and web site designer,
and author.
If you observe inaccuracies in our in-house
contributions or wish to contribute an article
or review to be included at AbleStable®
visit Feedback.
Copyright
Notice
Although our contents are free to browse, copyright
resides with the originators of all works accessed
at AbleStable®, and unauthorised copying
or publication of our site contents is strictly
prohibited.
AbleStable © 2002-2008 |
| |
 |
|
|
|
|
| |
|
|
|
|
 |
 |
| All
Material: AbleStable © 2002-2008 |
|
|

|