CGI

CGI stands for common gateway interface. It is provided so that webpage visitor can send data to the server. It is not easy to understand the concept of CGI. As briefly explained in the basic concepts page, CGI is a way to call .cgi executables on the server machine and display the result using a web browser:

  1. Normally when visitor inputs are needed, an html module called FORM is used to collect them.
  2. Upon visitor's submitting the data, a CGI request is made to the web server, carrying data as arguments.
  3. CGI requests may carries arguments with them and these arguments can be attached manually as part of the text in the address bar, or automatically through an html module called FORM.
  4. After hearing a request, the server program calls the corresponding .cgi executable with the arguments.
  5. The execution of this program generates an html page.
  6. The .cgi executable then processes these arguments and generates a result web page.
  7. The html page is returned as normal html page to the browser.

The .cgi executable can be written in any language. But the majority of them tend to be scripts, written using either the Perl programming language (powerful but complicated, recommended by our CSG), PHP (easy but sometimes too simple, therefore not recommended), or Python (yet another powerful scripting language.) Any .cgi executables in your public_html directory must have the suffix .cgi and need to meet the following conditions:

  • It must be readable and executable by you.
  • If it is writable, it must only be writable by you.
  • The file must be owned by you, and it must have the same group as your primary group
  • The directory containing the file must only be writable by you
  • The directory containing the file must also have the same group as your primary group

The best way to ensure that these conditions are met is to run the following commands in Linux:

  • chmod 755 executablename
  • chmod 755 .
  • chown -R yourusername *

Note that if executables are scripts*, they must be in Unix format, not Windows. The Programmer's File Editor ( Start -> Programs -> Editors -> PFE ) on Windows workstations has an option under "File/Save As" to use Linux format, or from the Linux command line dos2unix can be used to convert Windows files.

We are going to demonstrate how to use FORM and perl script to enable your website keeping visitor messages.

Next step, let's look at how to use FORM.