Common Gateway Interface

This is a brief lesson in setting up a Common Gateway Interface (CGI) based web page in Please read CGI Forms first. Then read this and then come back to CGI Forms and it should make more sense.

The idea in using CGI is that you will ask a server to run a program that will generate a web page, rather than simply copying a preformatted web page and delivering that to your computer (the client). In order to make this happen you need to send a URL that the server will intepret as a command to be run instead of as the name of an exsiting web page. Most commonly the necessary URL comes from an achor link or from a form on another web page, but you can simply type the necessary URL in for get-method CGI scripts. For the post method you have to use a form. Which method to use depends on how the script is written.

Let is start with writing the CGI script. This has to be a program on arcib. You need to place it into the files on your own account, and it has to be in public_html/cgi-bin. So, the first time you do this, immediately after you log in do:

mkdir public_html
cd public_html
mkdir cgi-bin
cd cgi-bin

After that, when you want to work on your CGI scripts, you just need to go to public_html/cgi-bin.

cd public_html/cgi-bin

which first takes you back to your home directory and then to public_html/cgi-bin

The program you write needs to be able to get information that has been sent to it on forms. If you are going to write your CGI script in python, see Python CGI, but in any language the idea is to pick up whatever data the user provided with the CGI URL and make it available to your code.

Once you have written your program, but sure to make it executable. If the name of the program is, be sure to do

chmod 755

That tell the system that you should be allowed to read, write and execute the program and the everybody else should be allowed to read and execute the program.

Once you have you program and have tested it directly, you may wish to make a web oage that will use a form to call it. The web page does not go into public_html/cgi-bin. It goes into public_html.

If you go back to CGI Forms you should now be able to follow the example and do it yourself in your arcib account. Just be sure to use your user name, not bernsteh.