Configuring Windows 2000 IIS for CGI

December 15, 2008
Filed under: CGI, Featured, Windows 

· Install Windows Internet Information Server (IIS) (Windows XP screen shots)

  1. Start > Settings > Control Panel > Add/Remove Programs
  2. Add/Remove Windows Components

Check the box for Internet Information Server (IIS); click the “Details…” button to select IIS components:

Windows XP

These are the components I installed, however you should not need FTP or SMTP if you only want to test CGI scripts:

Windows XP

Windows XP

[TOP]



·

Test the Server

  1. Assumptions:
    • %SystemDrive% = C: <!–
    • %SystemRoot% = C:WINNT –>
    • %UserDomain% = LOCALHOST

Use the SET command in a Command Prompt window to check your settings.
Make applicable adjustments if %SystemDrive% or %UserDomain% have different values on your system.

  1. Create a simple HTML document in the default server directory.

server_test.html in the default server directory C:Inetpubwwwroot

<html>
<head>
<title>Server Test</title>
<!-- server_test.html -->
</head>
<body>
The server is working
</body>
</html>
  1. Enter http://localhost/server_test.html in your browser to test the server

If the IIS is installed and working you should see your test document displayed in the browser:

Testing Internet Information Server (IIS)

· [TOP]



·

Install Perl

Download a current Perl binary distribution from www.activestate.com
The following are direct download links for ActiveState’s binaries for recent major versions of Perl. You may want to install more than one version depending on your need/desire to have a version compatible with the Perl you use on a Unix system.

Other ActiveState links:

See Introduction to Perl for additional information about installing ActivePerl and other Perl binary distributions on Windows operating systems.

[TOP]



·

Configure the Server

  1. See assumptions under “Test the Server” and make adjustments as necessary
  2. You must be logged on as Administrator to configure IIS
  3. The default location for CGI scripts is C:InetpubScripts
  4. The URL to access scripts is http://localhost/scripts/script_name
  5. Start > Settings > Control Panel > Administrative Tools Internet Services Manager
    Note: You may find it convenient to drag the Internet Services Manager menu item to the Desktop with the right mouse button and create a shortcut.
  6. Click on the “+” to expand *localhost in the left pane

Right-click and select Start or Stop as required to start or stop services.

Starting and Stopping localhost services

  1. You only need Default Web Site to test CGI scripts. For security reasons you probably want to stop the services except when you are testing scripts so your server is not open to the Internet if you have an “always on” connection.

Click on Default Web Site in the left pane to expand all the items in the right pane; right-click
on the Scripts folder and select Properties;

Click the “Create” button in the Virtual Directory tab so that the “Configuration” button is available (the “Create” button will change to “Remove”:

IIS Virtual Directory tab after clicking 'create'

  1. Click the “Configuration” button and look for Perl file extensions in the App Mappings tab (usually .pl and .plx)
    If you are using a Perl binary other than ActiveState, or if you installed ActivePerl from a ZIP file rather than the Windows installer, the extensions for Perl source files will probably not be present, in which case use the “Add” button to add a new mapping

Select the .pl extension and click the “Edit” button or, if no Perl extensions were listed, click the “Add” button.




Perl and Python extensions in the Virtual Directory App Mappings tab

Edit or Add a new Application Extension Mapping as follows:

Perl extensions in the Virtual Directory App Mappings tab

j. Notes:

    • Edit the path to your Perl executable as required.
      You may have multiple Perl installations; edit the path to reflect the installation/version you are currently using.
    • The ActivePerl installation does not include the -T switch to perl.exe as shown; however it must be part of the command line if you use it in the shebang line in your scripts.
      If you are adding a new extension mapping be sure to include the -T switch.
    • If adding a new Application Extension Mapping be sure to enter the fields exactly as shown. Note in particular the arguments “%s” %s. I cannot find any definitive documentation for the syntax, but this is what works.

[TOP]



·

Test the Server and CGI

Create a simple Perl script named cgi_test.pl in C:InetpubScripts as follows:

#!/usr/bin/perl -T
# cgi_test.pl
 
use warnings;
 
print "content-type: text/htmlnn";
    # Important! extra blank line after header
print "CGI is working";
  1. Enter http://localhost/scripts/cgi_test.pl in your browser

If CGI and the Perl script are working you should see the following displayed in the browser:

Testing CGI

c. Notes:

    • Under Windows and IIS the path information in the shebang line is not required or used;
      #!perl -T
      is perfectly valid.
    • However. if you are testing scripts that will ultimately be uploaded to a Unix server you may want to use the same shebang that your Unix server requires, such as
      #!/usr/bin/perl -T
      Windows will read the command line switches and ignore the path.

[TOP]



·

Internet Services Manager “Run As” Shortcut

You want to be able to manage IIS, such as starting and stopping services, but do not want to log off your user account, log on as Administrator to do a simple task, then log off and back on to your user account again. And you definitely do not want to do your daily development work in the Administrator account.

You could navigate to Internet Services Manager via the Start Menu, press the shift key while right-clicking on the Internet Services Manager menu item, and get the “Run As” prompt; however, better to create a shortcut to do all that for you.

  1. From your normal user account create a shortcut to Internet Services Manager
  2. Start > Settings > Control Panel > Administrative Tools > Internet Services Manager
  3. Holding down the right mouse button drag the Internet Services Manager menu item onto the Desktop and select “Create Shortcut(s) Here”

Right-click on the shortcut, select properties, and check the “Advanced” button.

Check “Run with different credentials”

Run with different credentials

When you use the shortcut you will be prompted for the user account and password to run the application. The default is Administrator, which is usually what you want.

Run As Other User

[TOP]



·

Create new IIS Virtual Directory

You want to be able to create, add, and edit scripts, however you do not want to do your development work under the Administrator account; and you do not want to log out of your user account, log on as Administrator to copy files to the default scripts folder, then log back on to your user account. Solution: create a IIS Virtual Directory that is accessible from your user account.

  1. Open the Internet Services Manager snap-in and create a new Virtual Directory
  2. Right-click on Default Web Site in the l

    eft pane, select New > Virtual Directory

  3. Work through the Virtual Directory Creation Wizard

Choose a Virtual Directory Alias (this will be the path following the LOCALHOST domain: http://localhost/usr-cgi

Virtual Directory Alias

Choose a Web Site Content Directory where you have access from your normal user account.

Virtual Directory Creation

When you get to the Access Permissions step in the Wizard be sure to check the “Execute…” box in addition to the Read and Run boxes already checked by default.

Virtual Directory Access Permissions

  1. After you have created the new virtual directory you must also configure it just like the Default Directory above. See 4. Configure the Server above.

Comments

Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!





*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image