Running Perl CGI Scripts with Windows httpd

This tutorial explains how to run CGI scripts written in Perl with your Windows httpd server. The information presented here is a simple variation of John Cope's wonderful Win-httpd CGI-DOS solution.

Here's the problem in a nutshell: Windows httpd is a Windows 3.1 server package that comes preconfigured to run Visual Basic CGI programs and MS-DOS batch (.bat) CGI scripts. Windows httpd is not preconfigured to run Perl scripts until you make a few modifications to your environment. The background section of John's solution explains this issue in detail.

Take the following steps to make the necessary modifications to your system:

  1. Download BigPerl; this is a freeware port of GNU Perl for the MS-DOS environment. Both Perl 4 and Perl 5 are available, but until all the bugs are worked out of the new version, we recommend Perl 4. If you want Perl 4, get the file named bperl4x.zip . For Perl 5, get all three ZIP files in the perl5 directory. (If those download sites are busy, try a mirror site.)

    Here's those URLs again, if you're reading this off-line:

  2. Install BigPerl. Here is our first deviation from John Cope's solution: you should unzip Perl 4 or Perl 5 so that the main files are in C:\PERL and the supporting library files are in C:\PERL\LIB .

    Perl 4:
    Unzip the distribution ZIP file from the C:\ prompt by typing PKUNZIP -D BPERL4X.ZIP . This creates the C:\PERL-4.036 and C:\PERL-4.036\LIB directories. Rename the first directory to C:\PERL, using the command MOVE PERL-4.036 PERL .

    Perl 5:
    Unzip the distribution ZIP files from the C:\ prompt by typing PKUNZIP -D PERL5*.ZIP . This creates the C:\PERL-5.000 and C:\PERL-5.000\LIB directories. Rename the first directory to C:\PERL, using the command MOVE PERL-5.000 PERL .

  3. Download John's CGI-DOS package to the directory of your choice, and unzip it. Copy the files CGI-DOS.PL and CGI-LIB.PL to C:\PERL\LIB .

  4. Add the following lines to your AUTOEXEC.BAT file:

    SET TEMP=C:\SYSTEMP
    SET COMSPEC=C:\DOS\COMMAND.COM

    PERL5 users should also add the line
    SET PERLLIB=C:\PERL\LIB

    Be sure that you don't already have TEMP and COMSPEC defined. Also, be sure that there is a copy of COMMAND.COM in your C:\DOS directory.

  5. Add C:\PERL to the PATH statement in your AUTOEXEC.BAT file.

  6. Use the Windows PIF editor (in the "Main" program group) to create the file C:\HTTPD\HSCRIPT.PIF with the following information:

    Program Filename: %COMSPEC%
    Window Title: perlVM
    Optional Parameters: /cPERL.EXE
    Start-up Directory: %TEMP%
    Video Memory: Low Graphics
    Memory Requirements: KB Required 640 ; KB Desired 640
    EMS Memory: KB Required 0; KB Limit 1024
    XMS Memory: KB Required 0; KB Limit 1024
    Display Usage: Windowed
    Execution: Background
    Close Window on Exit: Yes (check the box)

    You shouldn't need to use the Advanced features. Also, you'll want to increase the memory limits if your system has more than 8M of memory and your Perl scripts demand it.

    When you save this PIF, you will get a warning message. Just click on "OK".

  7. Edit the file C:\HTTPD\CONF\HTTPD.CNF so that you have the following declarations:

    #
    ShellExec HSCRIPT.PIF
    #
    ShellExecOption /cPERL.EXE
    #
    ShellInitCmd $serverroot = 'c:/httpd';
    #
    ShellEnvFmt $ENV{'%s'} = '%s ';
    #
    # The space after the %s is required.
    #
    ShellScriptTempl @ARGV = '~a'; require 'cgi-dos.pl';
    #
    
    Of course, if your server root is on a drive or directory other than C:\HTTPD , put in the correct location, replacing backslashes with front slashes.

  8. You may want to increase your command environment space by adding the following line to your config.sys file. (I needed this before upgrading to DOS 6.2).
    SHELL=C:\DOS\COMMAND.COM C:\DOS\ /E:1536 /p

  9. Reboot your system.

  10. Start Windows HTTPD without ANY command line options (particularly the -x option).

That should do it. Be sure to put your Perl scripts in the C:\HTTPD\CGI-DOS directory and reference them with http://your.server.name/cgi-dos/your-program.pl .


If you have any problems with this procedure, please let us know and we'll try to find the problem and post updated instructions here if necessary.


Return to The Web Server Handbook's companion Web site.