Sun Java System Web Server 6.1 SP11 Administrator's Guide

Installing CGI Programs

This section discusses how to install CGI programs. The following topics are described:

In addition, the following sections discuss how to install Windows-specific CGI programs:

Overview of CGI

CGI programs can be defined with any number of programming languages. On a UNIX/Linux machine, you’re likely to find CGI programs written as Bourne shell or Perl scripts.


Note –

Under UNIX/Linux, there are extra CGIStub processes running that the server uses to aid in CGI execution. These processes are created only during the first access to a CGI. Their number varies depending upon the CGI load on the server. Do not kill these CGIStub processes. They disappear when the server is stopped.


For more information see the discussion regarding MinCGIStub, MaxCGIStub, and CGIStubIdleTimeout in the online Sun Java System Web Server 6.1 SP11 Performance Tuning, Sizing, and Scaling Guide.

On a Windows computer, you might find CGI programs written in C++ or batch files. For Windows, CGI programs written in a Windows-based programming language such as Visual Basic use a different mechanism to operate with the server. They are called Windows CGI programs. See Installing Windows CGI Programs for information about Windows CGI.


Note –

To run the command-line utilities, you need to manually set the Path variable to include server_root/bin/https/bin.


Regardless of the programming language, all CGI programs accept and return data in the same manner. For information about writing CGI programs, see the following sources of information:

There are two ways to store CGI programs on your server machine:

You can enable both options at the same time if desired.

There are benefits to both implementation. If you want to allow only a specific set of users to add CGI programs, keep the CGI programs in specified directories and restrict access to those directories. If you want to allow anyone who can add HTML files to be able to add CGI programs, use the file type alternative. Users can keep their CGI files in the same directories as their HTML files.

If you choose the directory option, your server attempts to interpret any file in that directory as a CGI program. By the same token, if you choose the file type option, your server attempts to process any files with the file extensions .cgi, .exe, or .bat as CGI programs. If a file has one of these extensions but is not a CGI program, an error occurs when a user attempts to access it.


Note –

By default, the file extensions for CGI programs are .cgi, .exe and .bat. However, you can change which extensions indicate CGI programs by modifying the MIME types file. You can do this by choosing the Server Preferences tab and clicking the MIME Types link.


Specifying a CGI Directory

To specify a CGI-only directory for a class of virtual servers, perform the following steps

ProcedureTo specify a CGI-only directory for a class of virtual servers

  1. From the Class Manager, choose the Programs tab.

    The CGI Directory window appears.

  2. In the URL Prefix field, type the URL prefix to use for this directory. The text you type appears as the directory for the CGI programs in URLs.

    For example, if you type cgi-bin as the URL prefix, then all URLs to these CGI programs have the following structure:

    http://yourserver.domain.com/cgi-bin/program-name


    Note –

    The URL prefix you specify can be different from the real CGI directory you specify in the previous step.


  3. In the CGI Directory text field, type the location of the directory as an absolute path. This directory doesn’t have to be under your document root. This is the reason that you need to specify a URL prefix in the next step.

  4. Click OK.

  5. Save and apply your changes.

    To remove an existing CGI directory, click that directory’s Remove button in the CGI Directory form. To change the URL prefix or CGI directory of an existing directory, click that directory’s Edit button.

    Copy your CGI programs into the directories you’ve specified. Remember that any files in those directories will be processed as CGI files, so don’t put HTML files in your CGI directory.

Configuring Unique CGI Attributes for Each Software Virtual Server

To specify CGI attributes for a single virtual server, perform the following steps

ProcedureTo specify CGI attributes for a single virtual server

  1. From the Class Manager, choose the Manager Virtual Servers button.

  2. From the Virtual Server Manager, choose the Settings link.

  3. In the CGI User text field, type the name of the user to execute CGI programs as.

  4. In the CGI Grouptext field, type the name of the group to execute CGI programs as.

  5. In the CGI Directory text field, type the directory to chdir to after chroot but before execution begins.

  6. (UNIX only) In the CGI Nice text field, type an increment that determines the CGI program’s priority relative to the server. Typically, the server is run with a nice value of 0 and the nice increment would be between 0 (the CGI program runs at same priority as server) and 19 (the CGI program runs at much lower priority than server). It is recommended that you do not increase the priority of the CGI program above that of the server by specifying a nice increment of -1.

  7. In the Chroot Directory text field, type the directory to chroot to before execution begins.

  8. Click OK.

  9. Save and apply your changes.

Specifying CGI as a File Type

To specify CGI programs as a file type, perform the following steps

ProcedureTo specify CGI programs as a file type

  1. From the Class Manager, choose the Programs tab.

  2. Click the CGI File Type page.

    The CGI as a File Type window appears.

  3. From the Editing picker, choose the resource you want this change to apply to.

  4. Click the Yes radio button under Activate CGI as a File Type.

  5. Click OK.

  6. Save and apply your changes.

    The CGI files must have the file extensions .bat, .exe, or .cgi. Any non-CGI files with those extensions are processed by your server as CGI files, causing errors.

Downloading Executable Files

If you’re using .exe as a CGI file type, you cannot download .exe files as executables.

One solution to this problem is to compress the executable files that you want users to be able to download, so that the extension is not .exe. This solution has the added benefit of making the download time shorter.

Another possible solution is to remove .exe as a file extension from the magnus-internal/cgi type and add it instead to the application/octet-stream type (the MIME type for normal downloadable files). You can do this through the Server Manager, by choosing the Server Preferences tab and clicking the MIME Types link. However, the disadvantage to this method is that after making this change you cannot use .exe files as CGI programs.

Another solution is to edit your server’s obj.conf file to set up a download directory, where any file in the directory is downloaded automatically. The rest of the server will not be affected.