Sun Java Sytem Web Server 7.0 blogs Amit's Weblog

Monday Jul 02, 2007

Configuring ShellCGI Configuring Perl CGI on Sun Java System Web Server 7.0

There have been lots of questions in the Sun Developer forums about running Perl programs as CGI applications on Sun Java System Web Server 7.0 especially on Windows. So I thought of briefly touching upon how to go about it.

Configuring Sun Java System Web Server to run Perl progams as CGI applications on Windows is just a matter of performing few simple tasks via Administration GUI/CLI. But before we get on to listing the steps for the same, let us try to understand couple of things.

Overview of Shell CGI Programs for Windows


Shell CGI is a server configuration that lets you run CGI applications using the file associations set in Windows.

For example, if the server gets a request for a shell CGI file called hello.pl, the server uses the Windows file associations to run the file using the program associated with the .pl extension. If the .pl extension is associated with the program C:\\bin\\perl.exe, the server attempts to execute the hello.pl file as follows:

c:\\bin\\perl.exe hello.pl

The easiest way to configure shell CGI is to create a directory in your server’s document root that contains only shell CGI files. However, you can also configure the server to associate specific file extensions with shell CGI by editing MIME types from the Sun ONE Web Server.

Setting Windows File extensions (Example)

Here is an example of how you could go about setting file extensions on windows.
Open a command prompt (as Administrator account) and follows the steps mentioned:

C:> assoc .pl=PerlScript
C:> ftype PerlScript=C:\Perl\Perl.exe %1 %*

Write a simple perl script and name it as say test.pl.

#!/usr/bin/perl
print "Content-type: text/html\n";
print <<HTML;
<html>
<head>
<title>A Simple Perl CGI</title>
</head>
<body>
<h1>A Simple Perl CGI</h1>
<p>Hello World</p>
</body>
HTML
exit;

Now test the cgi script as follows:

C:> test.pl
Content-type: text/html
<html>
<head>
<title>A Simple Perl CGI</title>
</head>
<body>
<h1>A Simple Perl CGI</h1>
<p>Hello World</p>
</body>



Note that file associations for different users can be different. For more information on setting Windows file extensions, see your Windows documentation.


If you have set up the file association sucessfully, we are ready to go about configuring the Sun Java System Web Server to run you Perl progams as CGIs.

Configuring Sun Java System Web Server 7.0 via Administration GUI
Let us start with Administration GUI of Sun Java System Web Server. The steps are as follows:

  •  Login to the Administration GUI
  • You will see a bunch of common tasks for the configuration and the virtual server in the Common Tasks Page. Select the configuration and virtual server for which you want to configure the Shell CGI.
  • Click on the "CGI Directories" link under the Virtual Server Tasks. This will take you to CGI Settings Page.
  • Click on "New.." button under the "CGI Directories" table. This action will bring up a pop up window
  • Specify a "URI Prefix" and the "Directory" where you are going to store your Perl programs. Also, check the Shell CGI radio button and click on "OK" button.

Shell CGI

  • Deploy the configuration by clicking the "Deployment Pending" link on the top right side of the page.
That is it!!. Sun Java System Web Server is ready to run your Perl programs as CGI applications. Create a directory which you have specified while creating the Shell CGI. In our example, we have specified ..\docs\shell-bin which imples that we have to create a directory shell-bin under <install-root>\https-<config>\docs\. Dump all your Perl scripts under this directory and and start the instance to let it run your favourite Perl scripts as CGIs.


Note -
Perl programs can have any file extension e.g .cgi, .bat, .pl. Sun Java System Web Server will be able to run Perl program (with any file extension) as CGI successfully as long as there is a valid file type association associated with the file extension.



Configuring Sun Java System Web Server 7.0 via Administration CLI
Let us now try to do the same set of tasks via Administration CLI.
  • Login to the Administration CLI.
  • Use the following CLI command to create a shell CGI directory:

    wadm> create-cgi-dir --config=<config> --vs=<vs_ name> --uri-prefix=<uri-prefix> --directory=<path> --shell-cgi

  • Deploy the configuraiton by invoking the following CLI command

    wadm> deploy-config <config_name>


Comments:

interesting, but could you do the same example on solaris? it doesn't work for me
thanks

Posted by gerard on August 28, 2008 at 12:46 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed