Web Teacher Software
web database
Javacript 
Tutorial
CGI tutorial
web 
database consulting
web database training
contact us about web 
database software
press
Hosted Database Solutions
webteacher home
Web Teacher Consulting
CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl

WHAT IS A CGI?

CGI stands for common gateway interface. Essentially, a CGI is just a program which runs on your server. It can be written in any programming language, so long as you can run it on your server. Perl has become a popular choice for CGI programming because it is available for all platforms, and it has many useful tools that are ideal for the web.

When I fill in a form on a web page and press 'Submit', 2 things happen on the server.

  1. Everything I typed or selected is copied to the server.
  2. The server looks for the program specified at the top of the form, and runs it.

The first thing the program will usually do is request the contents the web page form, and assign it to variables which it can use. Then the program is able to search a database or send an e-mail or add to a guestbook, or whatever you would like it to do.

As with the JavaScript tutorial, this tutorial will teach by example. For each new topic, we will examine the entire code, then break it down into small pieces and discuss the relevance of each line. Before you can use Perl on a Unix server, however, you will need to know a little bit about Unix.

THE UNIX ENVIRONMENT

You must have the ability to Telnet to your Unix server in order to create CGIs with Perl. Click here if you do not know how to do this.

You must have the ability to FTP documents to your server. You probably have already done this, as it is necessary to publish anything on the web.

There will be times when using Unix when it will seem that we have traveled 20 years back in time. The editors and commands are typed on a command line, as we did with DOS. Actually, Unix is by far the most powerful and flexible operating system available. When used at a local terminal, users use a graphic interface called X-Windows. X-Windows is too slow to use over the internet, however, so we will use the command line for the few Unix commands we need.

The command Prompt

Every time you enter a new line into Unix, you will get a command prompt. It often appears as your machine's name followed by a % or # symbol. This is where you enter your basic commands to create, copy, move, and delete files, among other things.

Click here for a list of basic Unix commands.
Print it out, and keep it close at hand.

Try this exercise:

  1. Open your favorite Mac or PC word processor. As with HTML, use a simple editor which can save your code as plain text. Type the following line: This is a dummy sentence.
  2. Save the file as practice.txt
  3. Use your FTP program to upload practice.txt to your server. NOTE: You should always upload your cgi files as ASCII, not binary.
  4. Use your TELNET program to access your web server.
  5. LOGIN with your user name and password.
  6. Type ls and press [ENTER] (NOTE: use lower case, UNIX is case sensitive) The contents of your web server should list on the screen. You should see practice.txt in the list.
  7. Type pwd and press [ENTER]. pwd stands for 'Print Working Directory'. The path from your server's ROOT directory to your current directory should be displayed. For example, my home directory is at /home/usr/robyoung/htdocs
  8. Type mkdir myfolder and press [ENTER]. You have just created a new directory (folder) called 'myfolder'
  9. Type mv practice.txt myfolder/practice.txt and press [ENTER]. This will move practice.txt into myfolder.
  10. Type cd myfolder and press [ENTER]. You have changed to the myfolder directory
  11. Type pwd and press [ENTER]. The path name now ends with /myfolder
  12. Type ls and press [ENTER]. The contents of myfolder is displayed. practice.txt is the only thing in it.
  13. Type cp practice.txt copy2.txt and press [ENTER]. You have made a copy of practice.txt called copy2.txt
  14. Type ls and press [ENTER]. 2 files are now listed.
  15. Type rm copy2.txt and press [ENTER]. copy2.txt has been deleted.
  16. Type ls and press [ENTER]. Only practice.txt remains.
BACKThe chmod | Locating Perl Program | emacs editor

Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room