Back          Home

Getting Apache and Perl to Work in Windows XP

If you are new to Perl and Apache, getting Apache to execute Perl scripts isn't as straightforward as many websites might lead you to believe. This article points out the high level steps you need to take in order to have Apache execute your server side scripts and return data to a client web browser using the Include Virtual CGI directive. If you have previously attempted to get Perl to work with Apache to support Server Side Includes, you may have noticed that only the examples that use the HTML POST command actually work.

This page was developed because the web resources that purport to get these two applications working together are either simply wrong, grossly inaccurate, or only give a single clue to a single step of what must be done when you really need all of the information together, unless you know to search for the esoteric SSI acronym.

      Download and Install Perl

ActiveState's ActivePerl is a quality-assured distribution of Perl, which is available for Linux, Solaris, and Windows. ActiveState provide ActivePerl free to the Perl user community.

Read the license agreement here.

Register for and download ActiveState's ActivePerl here.

Alternatively, just download without registering here.

Installation is very straightforward. Just follow the bouncing ball.

      Associate .CGI with ActivePerl

Once ActivePerl is installed, you will already have the .PL extension registered with Windows so that double-clicking a .PL file in Explorer, or simply typing the Perl script name in a CMD window, will execute the script. The problem is that Apache seems to be expecting .CGI files, not .PL files, so, after testing your ActivePerl installation, you must associate the .CGI extension with the Perl interpreter. The final step is to configure Apache to execute server side includes then do some testing.

Start Windows Explorer and from the Tools menu, select Folder Options, on the File Types tab click the New button and add the CGI extension. Note that no period is added before CGI;

There is no need to set the advanced options. Simply click OK once the extension has been typed in, then click the Change button and choose Select the program from a list;

Scroll down the list and select Perl Command Line Interpreter and apply your changes.

You should now be able to change the extension of one of the sample .PL scripts to .CGI and the script should execute when you double click it in Explorer or enter its name in a CMD window. Taking the latter option to test the association assumes either that the script is in your path or that your command prompt is running from the directory where the Perl script resides.

If the script that was renamed from .PL to .CGI executes, that's it for configuring Perl. If it doesn't execute, then retrace your steps and troubleshoot the cause. You may need to add .CGI and .PL to the PATHEXT Windows NT environment variable. To do this, select System from within the Control Panel and click Environment Variables, which lives on the Advanced tab;

      Download and Install Apache

These instructions were tested on both Apache 2.0.48 and Apache 1.3.29. Download your preferred version of Apache from one of the mirrors listed at apache.org.

Install Apache as per the instructions and make sure that the default website is being served. Once Apache is up and serving the default page, you can configure it to execute the Include Virtual directive properly.

      Configuring Apache

Edit the httpd.conf file and make the following changes;

  • AddType text/html .shtml

Enable the Apache AddType text/html .shtml directive. This allows you to use server-parsed HTML files. This entry is included in the configuration file, but is disabled by default.

  • AddHandler server-parsed .shtml

Enable the Apache AddType text/html .shtml directive. This tells Apache that every .shtml file should be processed for Server Side Include commands.

  • Options Indexes FollowSymLinks MultiViews Includes ExecCGI

There are two Options entries in the default httpd.conf file. The first is a set of very restrictive default features. The second is used to add supported features to your web page root, along with its subdirectories. Modify the second Options entry, the one for your DocumentRoot directory, to read;

Options Indexes FollowSymLinks MultiViews Includes ExecCGI

This setting causes the required Includes and CGI execution options to be permitted from your DocumentRoot directory and below.

  • ScriptInterpreterSource registry

This Apache directive alters Apache's default Unix behaviour so that the Windows registry is used to determine where scripts are to be executed from. With this setting, the ubiquitous #! /usr/bin/blah CGI directive that usually appears on the first line of CGI scripts should be ignored. If your tests fail, suspect this first and change the first line of your script to point to your Perl executable, perl.exe, e.g.;

#!c:/perl/bin/perl.exe

The feature setting is documented only in the httpd.conf for Apache 1.3.x. It is not mentioned in the configuration file for Apache 2.x. Note the forward slashes, as opposed to the normal backslash nomenclature.

      Testing CGI Server Side Includes on Apache

You should be ready to test your installation changes. Simply create a .shtml file with an Include Virtual directive that points to a valid .cgi file, then invoke the .shtml file from your browser.

Put your test .cgi file into the Apache cgi-bin directory, as specified by the ScriptAlias directive, e.g.;

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/"

Put your test .shtml file into your DocumentRoot directory, e.g.;

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"

Request the .shtml file via your browser.

      Obtaining More Information

Visit apache.org's Apache Tutorial: Introduction to Server Side Includes page for much more detail.

Back          Home

Revision Date: 29 Nov 2003   Site Meter