CMP 217 - C Programming Language CGI Generation and Installation Instructions

  1. Program generation.
    It has been my experience that generating the program in a windows environment is superior to that of command line / text editor. Since the target server (www.limit.sunynassau.edu) is not running the X-Windows package, it is probably better to generate the program in the Turbo package.

    Notes:

    • After entering the program, choose COMPILE to pick up syntax errors.
    • In most instances, CGI will not run unless it is going through a server or steps have been taken to dummy up the server environment.
    • SInce the source code will be moved to the server, you will have a natural backup. Be sure to keep source code synced. In particular, do not make changes to the server side source code without downloading back to the PC.
  2. Transporting the source code to the server.
    Once the source code has been written and compiled, one must move it to the server. This is usually done with a program using FTP (File Transfer Protocol). For Windows 95, etc, a program called WS_FTP makes for an easy interface. For information on using WS_FTP, see http://www.matcmp.sunynassau.edu/~glassr/html/ftp.htm

    Notes:

    • Initially, WS_FTP will connect you to your home directory, /home/your_account.
    • Be sure that when uploading your source code, you choose the ASCII button for the C source code.
  3. Compiling the source code in a UNIX environment.
    To compile under UNIX, one uses the cc command. From the prompt, type the line:
    cc name.c -o name.cgi
    This will generate an executable file called name.cgi

    Notes:

    • Simple instructions can be found on page 6 in K & R.
    • the .cgi suffix is purely a convention and is used by the server software to denote an executable program/
  4. Moving the executable to the CGI directory (folder).
    Most servers have a particular directory that will hold CGI programs. foe limit, that directory is
    /web/student-cgi-bin/coursename/youraccount
    See www.limit.sunynassau.edu/index.html#cgi for more information.

    To copy the executable file to the CGI folder, give the command:

    cp name.cgi /web/student-cgi-bin/coursename/youraccount
    The file can be moved to the folder by using mv rather than cp

    Notes:

    • The original C cource file could have been directly uploaded to the cgi directory but I am of the opinion that you shouldn't.
  5. Testing the CGI.
    Once installed, the cgi is now ready to be tested using Netscape or your favorite browser. Give the URL:
    http://www.limit.sunynassau.edu/student-cgi-bin/courseaccount/youraccount/name.cgi
    At this point, your browser should display the specified output of your program.

    Notes:

    • 400 Server Error occurs. Please do not contact the administator. There is nothing wrong with the server, it is your program. It could be a run time error or the Content-type was not given according to specifications.
    • A Forbidden error message occurs. This will happen if you specify a name other than the executable file.