Configure a Web Server for Perl / CGI Scripting

“CGI” stands for “Common Gateway Interface”. CGI is a popular method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. A CGI can be written in any programming language, but Perl is the most popular.

Running Perl Scripts on your Web Server

Although it does not ship with built-in support for executing Perl scripts, it’s easy enough to add Perl support to Internet Information Server.

Once the Perl interpreter is installed, you should be able to place Perl CGI scripts in any scripts directory, such as the default /scripts scripts directory. You can also create a new scripts directory, named cgi-bin for example, by physically creating an empty directory on the hard drive, adding it to the Internet Information Server manager and enabling the Execute attribute (Script attribute in Microsoft IIS 4.x).

Note: For security reasons, you do not want Perl.exe to exist in any directory that can be browsed from other computers. With a script mapping in the registry, you can place the Perl.exe outside of the normal directory structure and avoid such security risks.

Adding Perl Support to your Web Server
  • Make sure your web server is properly installed and functioning
  • Download and install Perl 5 for Windows
  • Configure Perl Script Maps
Microsoft IIS < 3.x; or Personal Web Server for Windows NT (discontinued)

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Use the Registry Editor at your own risk.

For information about how to edit the registry, view the “Changing Keys and Values” Help topic in Registry Editor (Regedit.exe) or the “Add and Delete Information in the Registry” and “Edit Registry Data” Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT or Windows 2000, you should also update your Emergency Repair Disk (ERD).

Update the registry as follows:

  • Start regedt32.exe and Open HKEY_LOCAL_MACHINE SYSTEMCurrentControlSet ServicesW3SVCParameters ScriptMap
  • Select “Add Value” from the “Edit” menu.
  • Set “Value Name” to .pl (or .cgi if you plan to name your scipts with a .cgi extention)
  • Set “Data type” to REG_SZ
  • Set “String value” to: perl.exe %s %s: for example, if you installed Perl in C:PERL, typec:perlbinperl.exe %s %s
Internet Information Server 4.x
  • Open “Internet Service Manager” for Microsoft IIS 4.x
  • Right click on the web server entry under the “Internet Information Server” folder and select “Properties
  • Restart all Internet Information Server services and/or restart the server machine.

Note: This will map the .pl file extension to the Perl interpreter on all directories under the selected web server. To enable Perl scripts on just a single virtual directory, select that directory instead and go to its “Properties“.
Select “WWW Service” under “Master Properties” and click on “Edit…
Change to the “Home Directory” tab Click on “Configuration…” Select “.pl” entry (or add one) and click on “Edit” Set “Executable” parameter to: perl.exe %s %s

For example, if you installed Perl in C:\PERL, type c:\perl\bin\perl.exe %s %s Apply changes and close “Internet Service Manager

Personal Web Server Running on Windows 95/98

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Use the Registry Editor at your own risk.

For information about how to edit the registry, view the “Changing Keys and Values” Help topic in Registry Editor (Regedit.exe) or the “Add and Delete Information in the Registry” and “Edit Registry Data” Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT or Windows 2000, you should also update your Emergency Repair Disk (ERD).

  1. On the Start menu, click Run.
  2. In the Open box, type Regedit and click OK.
  3. Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\ParametersScriptMap
  4. On the Edit menu, point to New, and click String Value.
  5. Name the value .pl and press ENTER.
  6. Select .pl, and click Modify on the Edit menu.
  7. In the Value Data box, type perl.exe %s %s
    NOTE: The “%s %s” is case sensitive (for example, “%S %S” will not work).
  8. Close the Registry Editor, and restart your computer.

NOTE: Some versions of PERL automatically add this registry key when you install.

Create a file with Notepad, and type the following lines of code. Save the file as testing.pl in a folder in your web. Make sure this folder is marked executable.

In Notepad, type the following:

   print "HTTP/1.0 200 OKn";
   print "Content-Type: text/htmlnn";
 
   print "n";
   print "n";
   print "n";
   print "n";
   print "n";
   print "

This is a test to see if Perl is Working

n";
   print "

n”; print ”

If you can see this, Perl is properly configured
n";
   print "n";
   print "n";
How to Test the Script

To test the script, browse to the Perl script in Internet Explorer. For example, if you placed the testing.pl file in a folder named cgi-bin in your root web, you would type the following in the Internet Explorer address bar:

http://localhost/cgi-bin/testing.pl

The third-party products discussed in this article are manufactured by vendors independent of Taltech; we make no warranty, implied or otherwise, regarding these products’ performance or reliability.

Contact Us