Configuring the Apache Web Server to Run Perl Programs on Windows

Listed below is information on how to configure the Apache web server to run Perl CGI programs on Windows machines. For information on installing and configuring Apache for Windows, please see the following:

Installing and Configuring Apache for Windows

For information on configuring Apache to run other programming languages such as PHP, Python, and Ruby, please see the following links:

PHP for Windows

Python for Windows

Ruby for Windows

 

Installing Perl

Perl needs to be downloaded and installed before continuing. Download the latest version of perl from

http://www.activestate.com/activeperl/

http://www.activestate.com/store/activeperl/download. You can leave the registration form blank and just hit continue to proceed. Download the windows msi installer. Run the installer. The areas of interest in the installer are the install location. If you are only running Perl on Windows machines, you can use the default location. If you also have Perl programs running on Linux or Mac OS X, you may want to change the install location to C:\usr. This will allow you to maintain portability in your programs. You can also check the box so that Perl gets added to the path, and check the box to create the perl file extension association. After the installer completes, you now have Perl on your machine.

Configuring Perl CGI in Apache

The next step is to use EditRocket to open the httpd.conf apache configuration file located in the apache install directory in the conf directory. Search the httpd.conf file for the line

Options Indexes FollowSymLinks

Add ExecCGI to this line. The line should now look like the following:

Options Indexes FollowSymLinks ExecCGI

Next, search for the following:

#AddHandler cgi-script .cgi

Uncomment this line by removing the # in front of the line, and add a .pl to the end of the line. The new line should look like this:

AddHandler cgi-script .cgi .pl

Now, the apache web server needs to be restarted. You can do this either via the Apache service located in the services control panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option. Once apache is restarted, you can run a test page to make sure everything is working correctly.

Running a test Perl CGI script

You can create a new Perl test page in EditRocket by selecting File - New From Template - Perl - Sample Web Page. This will bring up the following in a new editor tab:

#!/usr/bin/perl
print "Content-type: text/html; charset=iso-8859-1\n\n";
print "<phtml>";
print "<body>";
print "Test Page";
print "</body>";
print "</html>";
				

Make sure to change the !#/usr/bin/perl to the location that Perl is installed on your machine. By default, it would be #!/perl/bin/perl The new file should look like the following:

#!/perl/bin/perl
print "Content-type: text/html; charset=iso-8859-1\n\n";
print "<phtml>";
print "<body>";
print "Test Page";
print "</body>";
print "</html>";
				

You can now save this file as test.pl to the htdocs directory under your apache installation directory. You can access the test.pl page by entering the URL of your local apache server in a web browser. If you are running apache on a port other than port 80, make sure to include :port_number after the localhost:

http://localhost/test.pl