|
|
Getting Apache and Perl to Work in Windows XPIf 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.
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.
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;
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.
Edit the httpd.conf file and make the following changes;
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.
Visit apache.org's Apache Tutorial: Introduction to Server Side Includes page for much more detail. |