NYU Database Systems (Spring'2000)
Developing and Installing CGI programs
CGI (or Common Gateway Interface) is a common method for the
browsers to send data in web forms to the web servers, where the
data is passed to a program (specified within the page) for
execution. The screen output of that program is displayed back at
As simple as that.
You got help!
The following references list various HTML and Form
elements that can be used in your web page. Use any text editor
for creating the page (or even a page creation tool).
CGI details can be found here:
CGILIB: CGI programs need to extract the form
values from an environment variable called QUERY_STRING. You can
do this yourselves, or use any library of routines written by
others. I have collected one such library from the web, called,
libcgi.a, which you are welcome to link with and use in your
assignment and project. How? (this will work directly with C programs, if you
are writing C++, you need to change cgi.h a little bit)
- For C: Download the cgi.h and libcgi.a
files (don't view the .a file, use the "Save link" option on
- The entire library code and libcgi.a (FYI) are also available
as a tar file file (to untar it on UNIX: use "tar -xvf cgilib.tar")
- For C++ Programs: Download these files: cgi++.h
- The entire library code and libcgi.a for C++ (FYI) are also available
as a tar file file (to untar it on UNIX: use "tar -xvf cgilib++.tar")
- #include "cgi.h" in your .c files (cgi++.h for C++)
- For C: Use gcc with "-lcgi" argument to compile.
Example: "gcc test.c -L. -lcgi -o test"
- For C++: g++ test.cc -L. -lcgi++ -o test
- Now INSTALL the output program as described below.
Installing and Invoking CGI Programs at NYU SUN Machines:
You will need to do Steps 1-3 only once; Do Step 4 every time
you create a new version of the cgi executable program. Step 5
& 6 are done when you are creating the web page.
- Create a directory called "public_html" in your
home directory. (mkdir public_html)
- Create a cgi-bin directory within public_html (mkdir
public_html/cgi-bin -- from your home directory)
- Give public read and execute permissions to both
directories (and for any files you may keep within later)
(chmod -R 755 public_html)
- Copy your executable CGI program, and any data files it
may need, to the cgi-bin directory. (make sure that it
has the read/exec permissions set by doing "ls
- If this program is called, say, "test", then
the corresponding URL for invoking this program from the
web page is: http://cs1.cs.nyu.edu/cgi-bin/cgiwrap/user/test
(user is your login name on the sun machines)
- Store your HTML files (web pages) in the public_html directory (or a
For illustration, I have created a web page and a cgi program (test.c);
check it out for getting started.
URL of CGI Program invoked in response: http://cs1.cs.nyu.edu/cgi-bin/cgiwrap/poosala/test
Source code for test.c
Source code for test.cc (C++ version)
Any questions -- contact the TAs or me.
Vishy Poosala. 1/26/2000
Back to Course Home Page