Sun Java System Web Server 6.1 SP10 Getting Started Guide

Configuring Server to use CGI

This section uses a simple exercise to show how you can configure your server to use CGI.

For instance, you have a simple Perl program called that we want to use CGI on our web server to execute. When executed, this program will display the words “Hello World!” on a browser window.

ProcedureTo configure your server to use CGI

  1. Use a text editor to create a file called and copy the following lines into it (remember to substitute <server_root> with the absolute path to your server root directory), and save your changes:

    print "Content-type:text/html\n\n";
    print "Hello World!";
  2. Create a directory for this program. This directory is known as the cgi-bin directory, you can rename it if required.

    mkdir /opt/SUNWwbsvr/cgi-bin
  3. Copy the file into the /opt/SUNWwbsvr/cgi-bin directory

  4. Access the Server Manager interface on a browser and click on the Programs tab.

    Figure 8–1 Adding a CGI Directory

    Adding a CGI directory

  5. Click the CGI Directory link if the server is running on UNIX. For Windows, the WinCGI Directory link. Specify:

    • a URL prefix (to which clients will send requests). In this example, this is set to /cgi-bin

      • the CGI directory. In our example, /opt/SUNWwbsvr/cgi-bin.

    Caution – Caution –

    The server must have read and execute permissions to this directory.

  6. Click OK and then Apply to save and apply the changes.

    Open a browser window and (if your server is called acme, running on port 2222), type http://acme:2222/cgi-bin/

    This executes the “Hello World” script, as shown in Figure 8-2: Sample CGI Script:

    Figure 8–2 Sample CGI Script

    Sample CGI script