· Install Windows Internet Information Server (IIS) (Windows XP screen shots)
- Start > Settings > Control Panel > Add/Remove Programs
- Add/Remove Windows Components
Check the box for Internet Information Server (IIS); click the “Details…” button to select IIS components:
These are the components I installed, however you should not need FTP or SMTP if you only want to test CGI scripts:
| || |
Test the Server
- %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.
- Create a simple HTML document in the default server directory.
server_test.html in the default server directory C:\Inetpub\wwwroot\
<!-- server_test.html -->
The server is working
- 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:
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.
- Perl 5.005_03 — ActiveState Build 522
5.3 Mb download
- Perl 5.6.1 — ActiveState Build 635
8.6 Mb download
- Perl 5.8.0 — ActiveState Build 806
11.3 Mb download
Other ActiveState links:
See Introduction to Perl for additional information about installing ActivePerl and other Perl binary distributions on Windows operating systems.
Configure the Server
- See assumptions under “Test the Server” and make adjustments as necessary
- You must be logged on as Administrator to configure IIS
- The default location for CGI scripts is C:\Inetpub\Scripts\
- The URL to access scripts is http://localhost/scripts/script_name
- 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.
- Click on the “+” to expand *localhost in the left pane
Right-click and select Start or Stop as required to start or stop services.
- 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”:
- 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.
Edit or Add a new Application Extension Mapping as follows:
- 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.
Test the Server and CGI
Create a simple Perl script named cgi_test.pl in C:\Inetpub\Scripts\ as follows:
print "content-type: text/html\n\n";
# Important! extra blank line after header
print "CGI is working";
- 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:
- Under Windows and IIS the path information in the shebang line is not required or used;
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
Windows will read the command line switches and ignore the path.
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.
- From your normal user account create a shortcut to Internet Services Manager
- Start > Settings > Control Panel > Administrative Tools > Internet Services Manager
- 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”
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.
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.
- Open the Internet Services Manager snap-in and create a new Virtual Directory
- Right-click on Default Web Site in the left pane, select New > Virtual Directory
- 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
Choose a Web Site Content Directory where you have access from your normal user account.
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.
- 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.