ActivePerl FAQ

 

NAME

ActivePerl faq6 - web server info


DESCRIPTION

ActivePerl Web Server Configuration and Troubleshooting


What HTTP servers support ActivePerl?

Most Windows NT and Windows 95 servers that use the CGI standard or ISAPI will run ActivePerl scripts. The following servers are known to work with ActivePerl (known protocols in brackets):

Alibaba from Computer Software Manufaktur [CGI, ISAPI]
    http://alibaba.austria.eu.net/
Apache for Win32 [CGI, mod_perl]
    http://www.apache.org
    mod_perl home page: http://perl.apache.org
EMWAC Web Server [CGI]
    http://emwac.ed.ac.uk/html/internet_toolchest/https/contents.htm
Microsoft Internet Information Server [CGI, ISAPI]
    http://www.microsoft.com/iis/
Netscape Enterprise and FastTrack Server [CGI, nsapi_perl]
    http://home.netscape.com/
    mod_nsapi home page: http://interact.canoe.ca/~bsugars/nsapi_perl.html
O'Reilly WebSite Professional [CGI, ISAPI, WSAPI]
    http://software.ora.com/
Purveyor by Process Software [CGI, ISAPI]
    http://www.process.com/

There's a list of web servers for Windows, Windows 95, and Windows NT on this Yahoo Page:

    http://www.yahoo.com/Computers_and_Internet/Software/Internet/World_Wide_Web/Servers/Microsoft_Windows_Windows_95/ 

(That's all one URL.)


How do I use ActivePerl under Apache?

If you want to put all of your CGI scripts into one directory, add the following line to your srm.conf file (You can choose any directory you'd like, but make sure it exists):

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

After you have made this change, stop and restart the Apache service.

Apache provides an emulation of the UNIX shebang (#!/path/to/perl) syntax, so the next step is easy. You can put you Perl scripts into your cgi-bin directory, as long as you have a path to a valid interpreter at the top. For example:

    #!C:\PERL\5.00464\bin\MSWin32-x86\perl.exe
     
    use CGI qw(:standard) ;
    print header();
    print "Hello, world";

If you want to enable CGI scripts based on an extension, such as .pl, you need to add the following line to srm.conf:

    AddHandler cgi-script .pl

By default, CGI scripts are not allowed in your DocumentRoot directory, but they are allowed in other document directories. Document directories are created with the Alias command in srm.conf:

    Alias /ResourceKit/ "E:/utilsamp/"

You can then include files that end in .pl within a document directory. You will still need to include the #! line with the full path to the perl.exe interpreter, as shown earlier.

If you want to allow CGI scripts in the DocumentRoot directory, add the ExecCGI option to the Options directive between the <Directory> and </Directory> entry for your DocumentRoot in access.conf (these appear directly after the comment titled:

    # This should be changed to whatever you set DocumentRoot to.
    
After you have updated it, your Options directive may look something like:
    Options Indexes FollowSymLinks ExecCGI

How do I configure the EMWAC https server to support ActivePerl?

First, read the EMWAC documentation:

    http://emwac.ed.ac.uk/html/internet_toolchest/https/scripts.htm

You need to follow these steps:

  1. Install ActivePerl.

  2. Install the EMWAC server. Ensure that EMWAC can serve HTML files correctly.

  3. Make sure that the bin subdirectory of your Perl directory is in the system PATH variable. This should be the subdirectory where perl.exe is located, such as C:\Perl\bin. Note that this must be set in the Control Panel, not on the command line, and it must be a system environment variable, not a user environment variable.

  4. Make sure that your script has the extension .pl. This is the only way that the https service recognizes the file as a Perl script.

  5. Ensure that the script is readable by the account used by the EMWAC server. Generally, this means you should make the script readable by the Everyone group.

  6. Ensure that all supporting files, like the perl binary files, the perl library files, and the modules that you use, are all readable by the account used by the EMWAC server (i.e., the Everyone group).

When the EMWAC server gets an HTTP request for a file with a .pl extension, it tries to execute perl [filename]. This is the only way you can get Perl scripts to work on the EMWAC server, so you need to follow the above directions.

By default, the ActivePerl installation puts the path to perl.exe in @INC.

Because the EMWAC server runs as a service (see What is a Windows NT service?), you need to take special steps to make files and environment variables like PATH accessible. Just because you can read a script and run it from the command line doesn't mean that the server can.


How do I configure IIS 3.0 or lower to support ActivePerl?

By default, the ActivePerl installation maps the .plx extension to Perl for ISAPI. You can override the extension used during installation. Because the installation does this only when IIS is already installed, you must install IIS first, then install ActivePerl. If you need to reconfigure these settings, or if you must set these by hand, the instructions in this section will prove useful.

Microsoft Internet Information Server (IIS) ships with Windows NT Server. Peer Web Services (PWS) ships with Windows NT Workstation. Configuring the products is essentially the same. First, you should consult Chapter 8, Publishing Information and Applications, in the IIS documentation.

You need to follow these steps to get ActivePerl scripts to run under IIS:

  1. Associate the extension for your scripts with the appropriate interpreter in the script map for IIS. This is under the Registry key HKEY_LOCAL_SYSTEM, with the sub-key ``System\CurrentControlSet\Services\W3SVC\Parameters\Script Map''. Many people map two extensions: one to perl.exe (for example, .pl) and another to PerlIS.dll (for example, .plx). Note that mapping an extension in the script map is not the same as associating the extension in Explorer. Use the full paths to the executable files in the script map.

  2. Put your scripts in a virtual directory on the server that has Execute access but not Read access. You can add virtual directories or view their access with the Internet Service Manager. Remember that the URLs for your virtual directories can't overlap with URLs to directories in the WWW root directory. For example, You can't have a cgi-bin virtual directory and a real cgi-bin subdirectory of the WWW root.

  3. Ensure that your scripts are readable by the account used by the IIS server. You set this account in Internet Service Manager; it is set to IUSR_[your server name] by default. See also What is a Windows NT service? and How do I set permissions on a file?.

  4. Ensure that all supporting files, like the perl binary files, the perl library files, and the modules that you use, are all readable by the account used by the IIS server. See also What is a Windows NT service? and How do I set permissions on a file?.

You need to restart the web service after making the Registry changes or installing Perl.

Because IIS runs as a service (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to it.


How do I configure Microsoft IIS 4.0 to support ActivePerl?

Microsoft IIS 4.0 ships with Windows NT Server 5.0, and PWS 4.0 ships with Windows NT Workstation 5.0. Both IIS and PWS are available as part of the Microsoft Windows NT 4.0 Option Pack. You can find a link to the Option Pack at http://www.microsoft.com/iis/

To configure IIS or PWS 4.0 to run Perl scripts:

  1. Open the IIS 4.0 Internet Service Manager. This will bring up the Microsoft Management Console with the Internet Service Manager snap-in selected.

  2. From the tree display on the left, select the level at which to apply the mappings. You can choose an entire server, web site, or a given virtual directory.

  3. Select Properties from the Action menu.

  4. If you chose to administer the properties for the entire server, the Server Properties dialog will appear. Select WWW Service from the Master Properties pull-down menu and click the Edit button under Master Properties. This opens WWW Service Master Properties. Select the Home Directory tab and proceed to step 7.

  5. If you chose to administer the properties for an entire web site, the Web Site Properties sheet appears. Select the Home Directory tab and proceed to step 7.

  6. If you chose to administer the properties for a virtual directory, the Virtual Directory Properties sheet appears. Select the Virtual Directory tab and proceed to step 7.

  7. Click the Configuration button. This opens the Application Configuration dialog.

  8. Select the App Mappings tab and click the Add button. You see the Add/Edit Application Extension Mapping dialog.

  9. To run Perl as a CGI application, type the full path to Perl.EXE followed by %s %s. When a script is executed, the first %s will be replaced by the full path to the script, and the second %s will be replaced by the script parameters.

  10. To run Perl for ISAPI, type the full path to PerlIS.DLL. The %s %s is not required for ISAPI DLLs.

  11. In the Extension field, type .pl or .plx (or whatever extension you want to use).

  12. The application mapping is now complete. Click the OK button and click OK to dismiss any remaining dialogs/property sheets.

  13. Close the IIS 4.0 Internet Service Manager.

Because IIS runs as a service (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to it.


How do I configure Netscape web servers to support ActivePerl?

If you're using Netscape 1.x servers, you must wrap your Perl scripts in batch files. Refer to these Netscape tech notes:

    http://help.netscape.com/kb/server/960513-3.html
    http://help.netscape.com/kb/server/960513-125.html 

The following information is for Netscape FastTrack Server 2.0. Other 2.0 and 3.0 Netscape Servers (Communications, Enterprise) should be similar.

To set up ActivePerl to run on FastTrack Server, follow these steps:

  1. Install FastTrack Server, and make sure you can retrieve HTML pages.

  2. Associate Perl scripts with the perl interpreter, if you haven't already. See How do I associate Perl scripts with perl? for how to do this. You may need to re-start the server after making the association.

  3. Set up a Shell CGI directory to run Perl scripts. A regular CGI directory will not work -- that is only for executable files. You set this up with the FastTrack Administrator; see the documentation for details.

If you would like to access Perl CGI scripts in other directories, you need to associate an extension, such as .pl, with the shellcgi MIME type. Before you follow these steps, you must add at least one Shell CGI directory - this will enable shellcgi on your server (you can delete this directory, and shellcgi will remain enabled). Follow these steps to associate .pl with the shellcgi MIME type:

  1. In the Server Administrator, click Server Preferences, then select MIME Types from the frame on the left.

  2. If you want to use .pl as the extension for Perl scripts, find and remove the application/x-perl MIME type (this is mapped to .pl by default).

  3. Add a new MIME Type with magnus-internal/shellcgi as the Content Type, and pl as the File Suffix. If a type for magnus-internal/shellcgi already exists, simply add pl to the list of File Suffixes. Don't include the leading dot on the file suffix.

  4. Save and apply these changes. You should be able to put a Perl CGI script in any directory, provided the script ends with the .pl suffix.

If you are having trouble running Perl scripts on your Netscape server, check the following:

One nice thing about FastTrack server is that the Error Log will give detailed reasons why your CGI script isn't running, so this is a good thing to check first when you are having configuration problems.

Because Netscape servers run as services (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to them.

Some people have reported problems with handling POST'ed data with Perl programs with Netscape servers. Since Netscape apparently uses associations to run scripts, and POST'ed data is sent on STDIN to a program. This may be related to the problems with redirection.


How do I configure WebSite 1.0 to support ActivePerl?

The following information is for setting up O'Reilly WebSite to use ActivePerl for standard CGI (not PerlIS).

  1. Install WebSite. Make sure you can retrieve HTML pages before continuing.

  2. Associate Perl scripts with the perl interpreter, if you haven't already. See How do I associate Perl scripts with perl? for how to do this. You may need to re-start the server after making the association.

  3. Set up a Standard CGI directory to hold your Perl scripts. You can use the Server Properties dialog box do to this.

  4. Ensure that the script is readable by the account used by the WebSite service. Generally, this means you should make the script readable by the Everyone group.

  5. Ensure that all supporting files, like the perl binary files, the perl library files, and the modules that you use, are all readable by the account used by the WebSite service (i.e., the Everyone group).

Because WebSite servers run as services (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to them.


How do I configure WebSite Professional to support ActivePerl?

The following information is for setting up O'Reilly WebSite Professional to use ActivePerl CGI (not PerlIS).

  1. Install WebSite Professional. Make sure you can retrieve HTML pages before continuing.

  2. Open Server Properties and click the Mapping tab. Server Properties is in the WebSite Professional folder on the Start menu.

  3. From the List Selector on the Mapping tab, choose Content Types.

  4. If there is an existing mapping for the extension you want to use (such as .pl), highlight the mapping and click Delete. Click Apply to immediately apply the change.

  5. Choose a file extension for Perl, such as .pl, and type it into the File Extension field. Make sure you include the leading period/full stop (.) in the file extension.

  6. Type wwwserver/shellcgi in the Media or Server-Side Content Type field.

  7. Click Add. Click Apply to immediately apply the change.

  8. Change the List Selector to Associations.

  9. If there is an existing mapping for the extension you want to use (such as .pl), highlight the mapping and click Delete. Click Apply to immediately apply the change.

  10. Type the file extension you chose in step 5 in the File Extension field. Make sure you include the leading period/full stop (.) in the file extension.

  11. Type the full path to Perl.exe, such as C:\Perl\5.00500\bin\MSWin32-x86\Perl.exe, in the Associated EXE or DLL field.

  12. Click Add. Click Apply to immediately apply the change.

  13. Close Server Properties. Reply appropriately to ``Terminate active connections and update the server settings?''. The server is now configured to execute Perl CGI scripts in directories marked as cgi-bin as well as document directories.

If you have trouble running scripts, ensure that the script is readable by the account used by the WebSite service. Generally, this means you should make the script readable by the Everyone group. Also, ensure that all supporting files, like the perl binary files, the perl library files, and the modules that you use, are all readable by the account used by the WebSite service (i.e., the Everyone group).

Because WebSite servers run as services (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to them.


How do I configure Purveyor to support ActivePerl?

The following instructions are for Purveyor 1.2 for Windows NT. Other Purveyor products should be similar.

  1. In the Purveyor Control Panel, use the CGI Mapping tab to map the .pl extension to perl.exe. Make sure that you use the full path to the executable.

  2. Also in the Purveyor Control Panel, use the Virtual Servers section to set your CGI Scripts directory. You need one scripts directory for each virtual server you support. The scripts directory must be in the data path for the server. Also, make sure that the Disable CGI Extension checkbox is unchecked.

  3. Ensure that the script is readable by the account used by the Purveyor service. Generally, this means you should make the script readable by the Everyone group.

  4. Ensure that all supporting files, like the perl binary files, the perl library files, and the modules that you use, are all readable by the account used by the Purveyor service (i.e., the Everyone group).

If you have problems while configuring Purveyor to use ActivePerl, you can use the Enable Tracing checkbox in the Logging tab of the Purveyor Control Panel applet to trace HTTP requests and responses.

Because Purveyor runs as a service (see What is a Windows NT service?), you need to take special steps to make sure that files and environment variables are available to it.


How do I configure Microsoft Personal Web Server 1.0x for Windows 95 to support ActivePerl?

Microsoft Personal Web Server for Windows 95 is a scaled-down version of Microsoft Internet Information Server. Although it is not documented, it appears that the method used to support ActivePerl with IIS will also work with Personal Web Server. See How do I configure IIS 3.0 or lower to support ActivePerl?.


How do I configure other web servers to support ActivePerl?

If your web server isn't listed, check the server's documentation on how to set up a CGI interpreter. In general the process is as follows:

Because most web servers run as services (see How do I configure IIS 3.0 or lower to support ActivePerl?), you need to take special steps to make sure that files and environment variables are available to them.


My program runs fine from the command line, but bombs out when run as a CGI script.

Usually, this means one of two things: either you have misconfigured your system, or your script does not output the right stuff to be a CGI script.

Before you do anything else, check this list:

Check the information above with a script that you know produces the right output for the CGI protocol (scripts in this FAQ are a good first choice). Try it with your own script after you're sure the test script will work.

If you are sure the server is running the script, but it only generates error messages in your browser, there are some tools that may help you out. CGI::Carp is used to send debugging information to the browser or log file. Even if your script has a compilation error, it can usually intercept and report errors. To use CGI::Carp, include the following lines in your program:

    # The stuff in the BEGIN block will be executed very early
    # on, even before the rest of this script is parsed.
    #
    BEGIN {
        
        # Use the CGI::Carp module and import the carpout() function.
        #
        use CGI::Carp qw(carpout);
        
        # Send warnings and die messages to the browser.
        #
        carpout(STDOUT);
        
    }

If your script has an error, you may see something like this in the browser:

    [Wed Jun 3 09:32:28 1998] C:\inetpub\scripts\test.pl: Error message! at
    C:\inetpub\scripts\test.pl line 38. 

Sometimes, it can be helpful to put yourself in somebody else's position. The libwww-perl bundle (LWP) is available from CPAN, but you can install it using the Perl Package Manager (PPM). LWP may be included with future releases of ActivePerl.

LWP includes the powerful lwp-request script, which lets you see things from the browser's perspective. Invoke lwp-request with the name of a URL to see the content of the response, as in lwp-request http://localhost. To inspect the headers of an HTTP response, invoke lwp-request with the -de switch:

    C:\>lwp-request -de http://localhost
    Date: Wed, 03 Jun 1998 13:37:31 GMT
    Accept-Ranges: bytes
    Server: Microsoft-IIS/4.0
    Content-Length: 4325
    Content-Location: http://localhost/Default.htm
    Content-Type: text/html
    ETag: "0c1e58b063bd1:1237"
    Last-Modified: Thu, 09 Apr 1998 12:09:28 GMT
    Client-Date: Wed, 03 Jun 1998 13:37:31 GMT
    Client-Peer: 127.0.0.1:0

This tool can be very helpful in figuring out exactly what your scripts are doing. Whatever you do, don't give up hope. It is, in fact, possible to get a Perl script running on your web server. Really.


This is all such a hassle; why can't I just put perl.exe in my CGI directory and use it in my URL?

First, the warning: DON'T DO THIS. REALLY. EVEN IF YOU DON'T UNDERSTAND WHY NOT, DON'T.

Now the explanation: the idea here is to put perl.exe in your CGI directory (however you configure that on your server), and use URL syntax like the following:

    http://soon.to.be.a.victim.net/cgi-bin/perl.exe?myscript.pl

to run myscript.pl. This keeps you from having to figure out how to configure your server to associate extensions like .pl with an interpreter like perl.exe.

In fact, on some early Win32-based web servers (Netscape 1.x servers in particular), it was impossible to associate a script file with an interpreter. This method was recommended by vendors as a viable approach to running Perl scripts on your web server.

Anyone with a devious mind and a little knowledge of Perl can see that with this configuration, hackers could start doing all kinds of horrible things on the server. All they'd have to do is send made-up URLs, using the -e command line switch in perl.exe, in order to do stuff like delete all files on a drive:

    http://aaaugh.that.hurts.net/cgi-bin/perl.exe?-e?'del%20c:\*.*%20/S%20/Q'

Of course, a true computer criminal would never do something so crude and obvious, but would instead use this as a launching point to cause irreparable harm to your organization.

The following URL covers this issue in more depth:

    ftp://cert.org/pub/cert_advisories/CA-96.11.interpreters_in_cgi_bin_dir

Tom Christiansen has also written a good discussion of the subject:

    http://www.perl.com/perl/news/latro-announce.html

Note that one suggested solution to this problem is wrapping your Perl script in a batch file using pl2bat or your own custom batch code. THIS IS ALSO NOT GOOD. Most of the primitive servers that won't allow file associations are also susceptible to a bug that allows a user to enter any DOS command after the bat file.

For more information on CGI and web server security, see these URLs:

    Web: http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html

As a final note, there are so many good, free web servers out there for Windows NT and Windows 95 that you should never stay with an old, insecure web server.


AUTHOR AND COPYRIGHT

This FAQ was originally assembled and maintained by Evangelo Prodromou. evangelo@endcontsw.com. It has been revised and updated by Brian Jepson of O'Reilly and Associates, and David Grove and David Dmytryshyn of ActiveState.

This FAQ is in the public domain. If you use it, however, please ensure that you give credit to the original authors.

 ActivePerl FAQ