473,473 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ


Configuring CGI Scripts

By Blair Ireland
Senior Editor, TheScripts.com

Configuring a CGI Script

In this article I will start to tackle one of the biggest newbie questions, how do I configure a cgi script for my site?

This is a pretty general question, and it's hard to answer this for all scripts, but I will give a general method to tackle this question with.

First of all, you must know the path to perl. Usually this is something you would ask your web host, but it is generally located in

#!/usr/local/bin/perl

or

#!/usr/bin/perl

If you have already opened up the script in question in your text editor (personally, I would recommend using Edit Plus, available at http://www.editplus.com/), check the opening line. If the path to perl is not correct, replace it with the correct path.

Next, you have to look at the certain variables used in the script.

The author usually highlights what each variable is, and what it should be set to.

Usually as well, these variables involve what are called full paths. I should explain what a full path is first though...

It is quite likely that you are using windows right now, so let me explain this with that in mind. Most likely, the actual windows executable file is c:\windows\win.exe. That is a full path.

UNIX uses a different method for a file system though. The paths generally look like /home/sites/yoursite/wuddever.

Now you are probably asking "How do I find the full path to my site on this computer?". You have two options, either ask your web host, or, put the following script on your server, run it, and it will output all of your environmental variables, including the path to your root web directory. Use this as your guide.

#!/usr/bin/perl
print "Content-type: text/html\n\n";
while (($key, $val) = each %ENV) {
print $key." = ".$val."\n";
}

Remember to copy and paste this into a file made from editplus or notepad, save it as paths.cgi, and upload it to your server in ASCII format, not binary. Chmod it 755 afterwards. Just access the URL to the script from your browser then, and voila!

Now, as you read through the variables you must set, make sure you don't kill the code while you fill them in. If there are quotes surrounding the variable, make sure they stay there, and that there is a semicolon at the end of each line.

After you do so, make sure you upload your script to the server in ASCII mode. Usually your ftp program will give you this option, you should see a button for it somewhere.

Once the script is on the server, make sure you chmod it 755. Test out your script... if it works, but not completely, usually your full paths are wrong. Go back and play around with them until you get it right.

 

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.