Greg's Blog

helping me remember what I figure out

Configuring Perl to Run on Apache (Win32)

| Comments

This document will highlight the changes necessary to get Perl to work with your Apache web server running on Windows NT/2000. As with the configuration of any other aspect of Apache, you will need to modify the configuration files. These are located in C:\Program Files\Apache Group\Apache\conf if you choose the default installation options.

The file you need to edit is srm.conf. When the server starts up it processes the httpd.conf first and then it will look for srm.conf. You will need to specify two things here. The first is the location of your CGI scripts. Next you will need to map the perl file extensions to your server. The srm.conf file looks initially like this:

#
# This is the default file for the ResourceConfig directive in httpd.conf.
# It is processed after httpd.conf but before access.conf.
#
# To avoid confusion, it is recommended that you put all of your
# Apache server directives into the httpd.conf file and leave this
# one essentially empty.
#

To implement the changes required make sure your config file looks like this:

#
# This is the default file for the ResourceConfig directive in httpd.conf.
# It is processed after httpd.conf but before access.conf.
#
# To avoid confusion, it is recommended that you put all of your
# Apache server directives into the httpd.conf file and leave this
# one essentially empty.
#
ScriptAlias /cgi-bin/ “C:/Program Files/Apache Group/Apache/cgi-bin/”
AddHandler cgi-script .pl

The first new line specifies the location of your cgi-bin directory (ScriptAlias) and the second line deals with the file extension mappings (AddHandler). For the changes to take effect stop and restart your server.

In order for your scripts to work you will need to specify the path of your Perl interpreter in your perl scripts. If you are running ActivePerl 5.6.0.613 (www.activestate.com) the default path should be C:\PERL\bin\perl.exe. So the opening line of all your Perl scripts should look like this:

#!C:\PERL\bin\perl.exe

Should you know wish to allow cgi-scripts to be executed from any other directories other than the cgi-bin/ directory you will have to specify an alias and the path to that alias. Again in the srm.conf file enter the following line if you wish to have an alias ”Scripts” for the directory called c:PerlScripts:

Alias /Scripts/ “C:/Perl/Scripts/”

Please note the use of “/” for the path definition instead of “”. You should be aware of the fact that you can also add these lines to the httpd.conf and the Apache documentation recommends this. However I find it easier to manage changes and information by keeping these modifications in a separate place. If you would like to test your installation try saving the following script in your script directory as hello.pl (please make sure that you make the appropriate changes to this script to reflect the location of your perl executable):

#!C:\PERL\bin\perl.exe

   use CGI qw(:standard) ;
   print header();
   print “Hello, world”;

You can now view this file by entering http://127.0.0.1/cgi-bin/hello.pl (or if you have been following the tutorials from this site the URL should be http://127.0.0.1:8081/cgi-bin/hello.pl). If all is working your browser should display the message Hello, world. Hope you found this quick introduction useful. All of it and much more can be found in the documentation provided with the Perl installation and these are located by default in the c:perlhtml.