How To Install A CGI Script
If you have surfed the net for some time now, you have repeatedly heard the acronym CGI. Well now I am going to show you how to install a CGI script for your own web page. In order for you to do this, you are going to need a web host that offers you a CGI-BIN so you can store your scripts there. If you have selected a good web host this shouldn?t be a problem. If not, refer to the Conference Room for any other guidance.
For the purpose of this article, we will assume that you are installing a PERL CGI script. You don?t have to worry about what that is yet; just know that it is written in a computer programming languages named PERL.
Things you will need and need to know.
You will need to know Perl, environmental variables, array and scalar variables and regular expressions. Did I scare you? Don’t worry, you don’t even need to know how to program to run and operate a CGI script on your site. In general, you only need to know the following to be able to install a CGI script.
How to use a text editor.
You must be able to work with an ASCII text editor as your script can only be written and edited in this. One such example is “notepad” on computers running windows.
The path to the PERL compiler.
On your web site’s server, there is a path to the PERL compiler. Take a look at the first line on your script. It should read something like this:
#!/usr/bin/perl -or- #!/usr/local/bin/perl
These are two common locations for a PERL compiler. REMEMBER that this line will always be at the top of your CGI script. You should make finding this information one of your priorities.
How can I do that? There are two ways of finding this information. The first is to “telnet” into your server using a windows program called “telnet”. Once inside you should type: whereis perl. When you get the response, write it down somewhere. The second is to contact your web host and ask them for this information.
The path to your site. NOT the URL.
While you are interrogating your web host, you should ask them the path to your web site. Since your site is on their server, it is located in a path that is unique to your web site. An example of this is:
DO NOT copy this example, as your path will be unique to every different web host. Unlike the path to your PERL compiler, this path differs in too many ways.
Other information that may be required.
Depending on the script you are using, it may ask for the path to your mail server.
You might also be required to enter the path of YOUR cgi-bin.
So in total, you are asking for the answers to 4 areas of your web site. Before you begin, you might consider going through your web host?s site, since these questions are asked frequently. They might be under a section entitled FAQ?s.
What do you do with all this information you just asked for? First off, open your script that you want to install using windows notepad. Here is an example of what it may look like (Not always):
# Script Name #
# Copyright 1998-99 by Someone #
# Email #
# http://www.website.com #
# Last modified Date #
# Copyright Notice:
# Here will include a long copyright notice
declare the variables
$maildir = ‘Enter your full mail directory here’;
$mailprog = ‘Enter the path to your mail program’;
$mailurl = ‘Set according to readme.txt’;
$yourname = ‘Enter your name’;
$yourmail = ‘enter your email’;
$cgi = ‘full path to the script’;
$queryswitch = ‘?’;
Usually your script will come in a *.zip format which requires you to use a compression tool. I recommend WinZip. In this file, once unzipped you will find a couple of files. In them should be one that is named readme.txt or info.dat. Open this file by double-clicking on it. If Notepad is not assigned to it now, do so.
This file contains the instructions on how to set up the script and what to do with it. Follow them as if your life depended on it. The creators of the script know their program inside out; I suggest you don?t second-guess them.
Uploading the script
Now we can begin uploading your script. Normally you should be able to FTP your script using any FTP program.
The two I recommend are CuteFTP and WS-FTP. You must upload the script to the CGI-BIN directory. Some things to keep in mind are:
Always upload using ASCII. Your script had to be written in ASCII so you must upload it using it as well. If you were to upload your script using a binary transfer, don’t be surprised if it doesn’t work. Consult your FTP program’s help files to change this.
After uploading change its permissions. This is also known as CHMOD or change file attributes. You should do this because, if the script ever fell into the hands of evil, you site would be at an incredible risk. I recommend that you read over the readme.txt for your script and see what it says.
The two most common chmod are 755 and 777.
In order to change these permissions, you need to have uploaded the cgi script in your CGI-BIN folder. This folder can be called by another name, but this seems the most common. If you have any questions, contact your web host.
Once you are done, right-click on your script to bring up a menu. Search for something that says “chmod” or “permissions.” Next should come an interface that allows you set the numbers accordingly. Change or CHMOD the file to whatever the readme.txt says.
Sit back and wait…
Now all you got to do is sit back and wait. NOPE, you’ll be waiting for a million years. You must activate your script. Depending on the type of script used, you can call it by using your browser. You should type the exact URL of your script in the navigational part of your browser.
Or if it is a form, you must edit the “action attribute” to incorporate this script. You must add the above URL to this attribute.
CONGRATULATIONS. You have now installed and configured a CGI script. Now that wasn’t rocket science, was it?