Installing and configuring CGI scripts for the layman.

You can use any FTP program to upload or download files to your webserver. One of the better FTP programs out is CuteFTP and can be downloaded free from the CuteFTP Website. This is a very simple program for even newbies to use.

The first part of any configuration of a CGI script is to find the location of the Perl interpreter on your server. You can get this information by using a telnet program such as CRT which is available from the VanDyke Website. Once you have your telnet application installed and you have successfully telnet'd into your webserver, you would issue the following command to locate Perl:

whereis perl

You should get an output with paths to perl on your webserver. Generally it will be one of these:
# ! /usr/local/bin/perl
or
# ! /usr/sbin/perl

Next we should locate the server path to your cgi-bin directory. There are several ways of getting this info also, as above. First, you can telnet into your webserver and change directory to your cgi-bin directory and type: pwd which will output the complete server path to that directory. If you do not have telnet then your FTP client may show the real path in its status bar. If not then ask your server administrator what the path is. A full server path might look like the following:
/home/user/public_html/cgi-bin

Next we will want the actual URL of the cgi-bin directory. Generally this would be something like: "http://www.domain.com/cgi-bin", in some cases it is much different and you may need to ask your server administrator what the exact URL is if you are unsure.

The next thing almost all scripts ask for is the server path of the sendmail program. This is used by CGI programs to send predefined output to you or others via email. The following is a general idea of where it could be.
/usr/sbin/sendmail

You can get the exact locations on your server via telnet by typing the following command:
whereis sendmail

Once you are equiped with the above items you are ready to begin actual configuration of your CGI script.

Open the README or install file in a text editor (we reccomend UltraEdit.) and start reading it carefully. Most decent authors include all kinds of comments and tips in their documentation, which should help you greatly.

Follow the installation instructions to the letter! You will be asked to open a .cgi or .pl file in your text editor. In any file of this type, you find the following

#!/usr/bin/perl

This line must be in your Perl CGI script as the first line. A 500 Server Error can occur if this is not the first line or if it is set to the wrong location. Copy the path of the perl interpreter on your server that we located above as the first line of your script, with the #! in front of it.

Next you should find lines setting the location path and URL of your cgi-bin directory. Change the cgi-bin path in this file to the one we found earlier. Follow any other Comments in the script. (All the lines which start with # are comment statements) Sometimes the author gives you a warning like "You should not edit anything below this". I would advise you to heed this warning.

Once you have done the first .cgi or .pl file you will have a general idea of how things need to be done. Now you may be asked to open other files and do the same process as the first. Do so, again following the installation instructions to the letter.

Okay a small bit on what a cgi-bin is and does, and why it is important.
The cgi-bin is a special directory on the server where are allowed to run interactive programs. Most webservers only allow programs inside of a cgi-bin to be executed. If the cgi-bin has not been enabled on your server, or if you don't have one, ask your system administrator to allow you to run CGI scripts on your server.

A cgi-bin is needed to run these scripts unless your system administrator has turned on ExecCGI in apache, which allows CGI scripts to be run from any directory under your root html directory. To find out if you can use CGI scripts, your best bet is to ask your system administrator if you can.

Next comes the tricky part, uploadloading. You can upload your script and any associated files after completing all necessary changes. There are two ways to upload files, ASCII and Binary. You need to upload any text file (non image) in ASCII mode. If you upload script files and text files in Binary it camn corrupt them and render them inoperable. Upload all image files like .jpg or .gif in Binary mode. If you accidentally upload script or text files in Binary, delete them on the server and re-upload them correctly in ASCII mode.

Next, you will need to set all file permissions for your script and associated files. This can be done in telnet or in most FTP clients. Refer to our telnet or FTP help areas for more info on this. Again, the scripts installation file *should* tell you exactly what to set the different files/directories permissions to.

Now we will attempt to run the script. The installation help file should tell you which URL you need to open. It could be a .cgi, .pl or an .html file. Open your web browser and enter that URL and see what happens. If you get an error, dont scream or rip your hair out just yet. This just means that something,usually minor, is wrong with how the script is set up. You need to double check everything from the beginning and look at your error logs if your system administrator provided you with them. Much of the time the error log can tell you exactly what is wrong with your installation.

Below are some common errors and what they could mean.

Error 500 or Internal server error:
This error can happen for many reasons.
   a) the script does not contain the "#!/usr/bin/perl" line that points to the Perl interpreter, or if the path to the perl interpreter (and/or a library file) is incorrect.
   b) the first line output from the script is not a valid HTTP header (i.e. "Content-type: text/html"), or there is no blank line after the header data (\n\n generally).
   c) there is a syntax error in your script. Always run it from the command-line first via telnet to see any errors in syntax.
   d) check to make sure that the ACTION="" of your script or HTML is pointing to the correct CGI program. If it is, make sure that this file is also chmod 755 so that everyone, including the Web Server has permission to execute it.
   e) make sure all files to be opened during execution by the script are chmoded so that the web server can read them or if needed write to them.
   f) check all paths and make sure they are correct. An incorrect path in your script will cause execution of your script to fail.

Error 403 "File Not Found"
Generally this is from a configuration error in which a path or url is set for a certain program or file is incorrect. Check all paths you have set in the cgi script configuration. Possibly this can be from a missing directory also, which the script may need to write to or read from.

Error 501 "Cannot POST to non-script area..."
Obviously, where you have the script installed or where the form ACTION="" tag is pointing to a location that the webserver does not recognize as a cgi-bin location. Contact your server administrator and ask him where the script should be installed.

Error 404 "File Does Not Exist"
This error is generally caused by the wrong path. Make sure that the path is to Perl. (Like " /usr/bin/perl") Also make sure that the path pointing to your script in your HTML document is correct.

This should help you with most configuration / Installation issues you may have. If it doesn't cover what you need, feel free to use our installation services and technicians. For a modest fee, we will install any script you own on your server for you.






Proud suppliers of perl cgi and php applications created from the webmasters point of view. PerlCoders supplies top quality CGI scripts at membership warehouse prices every day. This is the only webmaster resource you need to build traffic and add interactive content to any website.

Need custom programming or website development? We do it all. Just use our contact form and let us know what you need.

Perlcoders.com - Copyright © 2003 by PerlCoders Group
Privacy policy       Licensing policy       Site Usage Terms
Not a member yet?
Click Here
User:
Pass:
I forgot my password
  HomePage
Current News
Our Products
Our Services
FAQ & Docs
Support
Contact
Make Money!
Affiliate Login
 
Right now get access at a special rate of only $160 which includes more than 156 of our top quality CGI scripts and get deep discounts on many others. You also get full access to our members area which is slam packed with webmaster goodies.

  · Read more...


 
Get the latest News at
the Perlcoders group.

 
What our clients say
Tell us what you think
Projects in the works
Free scripts to members
Free self help ebooks
Free Tip of the Day
Free Support
Custom programming
Google Forum
SEO Forum
Myth of Caesar
SEO Resources
Cellulean
Image Hosting