Make your own free website on Tripod.com

[an error occurred while processing this directive]

Site Menu

HTML
Learn all about HTML, how to format text, add images, create tables, meta taga, and more!
.
JavaScript
Get the low down on JavaScript. See how to create popular JavaScript applications like drop down menus, clocks, dynamic messages, popup boxes, and more.
.
CGI
Concise, easy to follow introdction to CGI and how to install CGI scripts.
.
Web Design
A miscellanous section that includes various web design tutorials

 

123 Web Design!

CGI Introduction

CGI is an inescapable part of any cool and interactive web site. You want a message forum for your site? How about a feedback form, or a counter? As I found out, the only way to make these things happen is through CGI scripts. Make no mistake, CGI is not the only language when it comes to making your site cool and interactive (DHTML is another), but it's definitely the most important and one the web can't live without. After looking through this tutorial, you'll have a much better understanding of what CGI is in general, and also how to debug and install your own CGI scripts.

-Overview of CGI

So what exactly is CGI? CGI stands for Common Gateway Interface. Any script can be called a CGI script as long as it's installed on the server end. However, the majority of CGI scripts are written in Perl (with C being the next most common). If you want to write your own CGI scripts, you'll need to learn Perl. It is exactly the fact that CGI is installed on the server end that makes it able to do all those amazing things such submit a form, create a guest book or forum, keep track of and rotate your ads etc.  The server has the capability to redirect data to any email address, persist data, dynamically serve out different content to the browser, among many other things that the browser alone simply cannot do.

-What do I need to run CGI scripts?

Your web host must allow you access to a CGI-BIN. Most paid web hosts comes equip with a CGI-BIN, but there are only a few free hosts that packs in that same feature to their services. A few good free hosts that supports CGI are Hypermart and WebJump.

-Ok, I know I have access to a CGI-BIN...now what?

There are tons of free, quality CGI scripts on the internet, and all you have to do is grab and learn how to install them onto your site.  As daunting as installing a CGI script on your server may sound, it's actually quite easy, as I found out. Regardless of the script you're attempting to installing, the process is pretty much the same. I'll walk you through this process right now!

-What are the things I need to know in order to install CGI Scripts?

Let's see... Environmental variables, regular expressions, scalar and array variables, and SSI. Ok, I'm just kidding. The fact is, you don't even need to know any programming to have a complete CGI program up and running on your site. In generally, you only need to know and understand the following, regardless of what CGI script you're trying to install:

  1. How to use a text editor (such as Notepad)
    Ok, this should be a given to everyone here. But how does a text editor fit in with installing a CGI script? Everything! First and foremost, it's important to understand that CGI scripts are really no different than normal text files (except the former uses a file extension of .pl or .cgi). Both are written in ASCII format, and can be opened and viewed using any text editor.  Now, in order to install a CGI script, you'll need to configure it. That's where the text editor comes in. Use it to open and configure your CGI script.
    .
  2. The path to the Perl compiler on your web host
    Once opened, all hell breaks lose (just kidding). Take a look at the very first line of the script...it should look something like this:

    #!/usr/bin/perl

    Don't panic if your first line looks a different than the above...that's perfectly fine. The thing to understand is just what this line of mumbo jumbo is, and what you need to change (if at all) of it. #!/usr/bin/perl refers to the path of the Perl compiler on your server. It always appears as the first line in your perl script. This line needs to refer to the perl compiler on your server. If you're lucky, you won't even need to change a thing, as #!/usr/bin/perl actually correctly refers to the compiler on most servers. Another likely candidate is #!/usr/local/bin/perl. The point here is to find out for sure the path to the Perl compiler on your server. How do you do that? You could find this info on your own by telneting to your server (assuming you have telnet access), and type "whereis perl", or, let your mouth do the work, and simply ask your web host provider: "What's the path to the perl compiler on this darn machine?" Either way works.
    .
  3. The path to your site
    And while you're grilling your web host provider on where the Perl compiler is, you might as well throw in where your site is as well. Uh? Not the URL of your site (I sure hope you know that), but the path to it from your server's standpoint. Think of it like this. On the WWW, your site's address may be http://mysite.com/index.html. But on your hard drive where your site is stored locally, it may be referenced as
    file:///c|/mysite/index.html What you have to find out now is the path to your site as seen from the server your site's on point of view. An example would may look something like:

    /usr/local/etc/httpd/sites/mysite.com

    Please don't try copying the above line and changing a few things in hopes it'll match the path to your own site. Unlike the path to your CGI compiler, the path to a site is completely different from site to site, and yours is a unique string resembling nothing like the above.  To find out your site's path in the server, ask your host provider, or check the CGI help section of your web host's site (they usually have such a section).
    .
  4. Some other helpful things to know
    There are a few other things you may need to know, depending on the CGI program you'll trying to install. Your program may ask you the path of your server's mail program (ie: /usr/lib/sendmail), or your CGI-BIN (ie: /usr/local/etc/httpd/sites/mysite.com/cgi-bin), information you can obtain easily simply by opening your mouth and interrogating your web host provider. Before you do that, however, check the company's web site.

Once you've figured all these things out, it's a matter of opening the cgi file using your text editor, and filling in the blanks whenever the program says so. It may say "change the below to the path of your CGI-BIN." What do you do then? Put in /usr/local/etc/httpd/sites/mysite.com/cgi-bin, or whatever your CGI-BIN's path may be.