Introduction to CGI

CGI (Common Gateway Interface) is a standard for running external programs from a web hosting server. Unlike static HTML web pages, CGI allows retriving data and construct end result in HTML web pages before sending to the web server for serving the website visitor's request, this allow flxibility in handling data and results to be served dynamically. For example, you can build up a CGI script to access data stored in a database, retrieve and perfom some calculation and formating, then send the results as part of an HTML web page. It is not surprise that CGI scripts are popular and widely used on the internet.

There are lots of good books and web documents that serve as introduction to CGI. It is good to grab a book to go though in detail if you are keen to master thispowerful scripting language. The information below serve as basic summary of important points to remember when using CGI. Here are several links to web documents for a more in-depth introduction to CGI:

Important notes when using CGI scripts:

  • Other than those pre installed scripts seen in your CPanel hosting account, there are lots of open source programs as well as paid license scripts available on the internet to help building a powerful website.

  • Be sure to go though all important documentation in a particular script before attempt to using it. This can generally help avoid frequently seen problems and speed up your development process.

  • CHMOD ("Change Mode") is a standard Unix shell command that can change the file or folder permissions (note that files uploaded are default to 'rw-r--r--' 644 which is not sufficient for script execution, you will have to manually change the file permission to 'rwxr-xr-x' so that the execution permission is allowed for the script. The unix command 'chmod 755 scriptname' sets up this permission). Alternatively, The CPanel File Manager allows you to quickly change file /folder permissions, as do most FTP tools that mostly has this basic feature included.

  • Important - A short process : after uploading CGI scripts, be sure to change permission with CHMOD to 755 (double check with the script documentation). For example, you must CHMOD the pre-installed CPanel CGI EMail scripts to 755 before able to use them properly.

  • Most CGI scripts need to include the path to Perl (a scripting language engine for processing the script) and the path to sendmail (a popular HTTP mail engine installed in most *nix based servers). You can find this path information on the CPanel hosting account control panel.

  • Test your scripts thoroughly!