Advertisement

Tutorials

Home Tutorials Advanced Tutorial

CGI Script Installation Tutorial

9.Start installation now!

2.0/5.0 (1 votes total)
Rate:

Benny Alexander
December 23, 2004


Benny Alexander
Benny Alexander
Stylus Systems Article

Benny Alexander has written 1 tutorials for CGIDir.
View all tutorials by Benny Alexander...

Open the readme file in a text editor and start reading it carefully. Make sure you have the complete list of files that have to be installed. You can find it in the list of files from the Help Text file. (Mostly, script developers do this documentation to help you locate the missing files). If your download was successfully done without any interruption, you probably have all the files needed for installation. Let's learn how to use any script file with these 5 easy steps.

1. Follow the installation document. You will be asked to open a .cgi or .PL file in a text editor as the first step. In almost any file of this type, you find the following

# ! /usr/local/bin/path

This line must be in your Perl script as the first line to get it to run right. It often causes a 500 Server Error if this is not set as your first line or if it is set in the wrong place. Copy the path of Perl program in your server noted down during the previous lesson as the first line of your program, with' # !' in the front. Should this command fail, ask your system administrator if they have Perl installed on their server and to where you should point this line.
2. Keep reading the .cgi or .PL file, you'll find some lines telling about the directory path and URL settings of your cgi-bin directory. Change the cgi-bin path in this file to the one noted down. Follow the other instructions in the script file given as Remarks. (All the lines which you find that start with # symbol are remarks or comment statements) Sometimes the author gives you a warning like "You should not edit anything below this". Its advisable to follow these warnings. You make any changes violating this warning, at your own risk. Then, you may be asked to open some more script files to do the same settings as above. Go one step at a time carefully. It is easily done. Let us pause for a moment here and learn a little more about the cgi-bin.
The cgi-bin is a special directory in the server where we keep all the files which require security. Limiting access of CGI scripts to trusted users is necessary, since the CGI opens up a lot of security risks. Therefore, most web platforms only allow files inside of a cgi-bin to be executed. This can be changed. If the cgi-bin has not been enabled on your server, or if you don't have one, ask your system administrator to give you the privilege to execute CGI scripts on your server.
A cgi-bin is needed to run these scripts unless your system administrator has turned on ExecCGI, which enables .cgi extensions to be used in any directory. To find out if you can use CGI scripts, your best bet is to ask your system administrator if you can. He/She may opt to give you a cgi-bin in your directory, turn on ExecCGI or check your script and then place it in the server cgi-bin.
Just make sure you set all variables to reflect any changes you have to make to the location of files and scripts by double checking.
3. Now you are ready to upload. You can upload all the files after completing all necessary changes There are two modes of uploading, ASCII and Binary. You can upload the .cgi, PL, .confide, .cfg, .setup and .txt files in ASCII mode, because basically they are text. Upload any image files like .jpg or .gif in Binary mode. If you don't follow this you will not be able to execute the script. If you upload any script files in Binary mode it will crash the script too. If you find that you have done it accidentally, delete the server file and upload a fresh copy from your local hard drive, carefully this time!
4. Now you would like to change the permissions of the script files but first you need to know that this is place where people often make mistakes and fail in installing scripts. You should be clear about chmod(changing mode or permission), so don't skip this area.
File permissions allow read, write, and execute access to users based on their user identification (also known as uid), and their membership to certain groups. You can use the command: chmod to change a file's permissions. Here is an example:

chmod 755 form.cgi

Chmod is a UNIX command which changes the security settings for a particular file, giving users and groups permission to read, write, and/or execute certain files.
For the script files, you need to make them executable. The code for that is 755. You only need to do this once. When you FTP the file again, it will overwrite the old file but the permissions will stay the same. Also note that some FTP software (like WS_FTP) have a builtin option to let you change the permissions without having to telnet to the server. Your server however has to support that feature. If you are interested in setting permissions from your FTP program, keep reading this section for more information on exactly what the permissions numbers (755 or 666) mean; or you can jump ahead to step 5, if you are not curious.
After you chmod the file, type in ls Ls (that's Ls[space][dash]Ls) and it will show a directory listing. In WS_FTP you can view it by pressing the Refresh and DirInfo buttons. Notice that next to the .cgi files, there is something that looks like:

- r w x r - x r - x

For our purposes, we can ignore the first symbol. The "r" symbol stands for read. The "w" symbols stand for write. And the "x" symbols stand for execute. Now, the above line of symbols is actually divided into 3 categories. (Ignoring the first symbol as stated above) the first three symbols define the permissions for the file's user (probably you). The second set of three symbols define the permissions for the file's group. (If you and many other employees are working on a web project together, you might be set up on the server as a group so you can edit each other's work). The third set defines the permissions for everyone else ("others" or the "universe"). So by doing chmod 755 filename.cgi, you or your group can read, write, and execute the file. Everyone including the Internet browsers, can read and execute the file.
So what does the number 755 stand for? Notice that this has 3 digits. As you would expect, those 3 digits correspond to the three different sets of permissions (file's owner, file's group, and others). Here are what each individual digit stands for:

1 = - - x
2 = - w -
3 = - w x
4 = r - -
5 = r - x
6 = r w -
7 = r w x

Therefore: 755 = r w x r - x r - x (We don't have to bother about the leading character). For more about chmod visit here.

5. After you have the permissions set, jump over to your browser and try to run the script. Your installation help file will tell you which URL you need to open. It could be a .cgi, PL or a .html file. Now of course, according to Murphy's Law there will inevitably be some kind of internal server error. Don't panic. That just means that something (hopefully minor) is wrong with how the script is set up. You need to double check once again from the beginning and here is a check list that can help you.
      CGI scripts root directory path and URLs - Make sure its correct
      ASCII or Binary ? Which mode did you upload?
      Permissions of the script files, directory you created and other text files.
      Location of the files you uploaded.[Script files - Inside cgi-bin.Others probably outside]
      Did you miss any files?
      Make changes in all of them?
      Finish all the instruction in the list from your installation help file ?
      Some scripts are using SSIs.(Egs Poll/Vote scripts).If you run any Server Side Include(SSI) make sure your server is enabled with this facility.
After checking all of the above, when you run the script, did you get something other than the error message? Good! You are lucky this time and you can start working. Oh! somebody is saying that they haven't succeeded there. I really want to help you too.

We can pinpoint the problem from the type of error messages the browser gives. After submitting the entry via the form or opening the script file in the browser you may see an error message. Let us diagnose the problem, correct the script and, next time, let us stop the browser from screaming.


Add commentAdd comment (Comments: 0)  

Advertisement

Partners

Related Resources

Other Resources

image arrow