printenv.pl - Testing Perl CGI Environment

This section provides a tutorial on how to modify the Perl CGI test script, printenv.pl, and run it to verify Apache 2 Perl CGI configuration.

The verify my Apache and Perl integration, I modified the Perl CGI test script, printenv.pl, provided by the Apache 2 package:

1. Edit the test script C:\local\apache\cgi-bin\printenv.pl and modify the path name of perl.exe to be the actually location of the perl.exe program:

#!c:/local/perl/bin/perl.exe
##
##  printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}

2. Run the test script with a Web browser at http://localhost/cgi-bin/printenv.pl. I got this output:

COMSPEC="C:\WINDOWS\system32\cmd.exe"
DOCUMENT_ROOT="C:/local/apache/htdocs"
GATEWAY_INTERFACE="CGI/1.1"
HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9...
HTTP_ACCEPT_CHARSET="ISO-8859-1,utf-8;q=0.7,*;q=0.7"
HTTP_ACCEPT_ENCODING="gzip,deflate"
HTTP_ACCEPT_LANGUAGE="en-us,en;q=0.5"
HTTP_CONNECTION="keep-alive"
HTTP_HOST="localhost"
HTTP_KEEP_ALIVE="300"
HTTP_USER_AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; r...
PATH="C:\local\Perl\site\bin;C:\local\Perl\bin;C:\WINDOWS\system32...
PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
QUERY_STRING=""
REMOTE_ADDR="127.0.0.1"
REMOTE_PORT="2404"
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/printenv.pl"
SCRIPT_FILENAME="C:/local/apache/cgi-bin/printenv.pl"
SCRIPT_NAME="/cgi-bin/printenv.pl"
SERVER_ADDR="127.0.0.1"
SERVER_ADMIN="herong@localhost"
SERVER_NAME="localhost"
SERVER_PORT="80"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE=""
SERVER_SOFTWARE="Apache/2.2.25 (Win32)"
SYSTEMROOT="C:\WINDOWS"
WINDIR="C:\WINDOWS"

The output approved that my Perl CGI configuration are working correctly.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

Integrating Perl with Apache Web Server

 Downloading Apache HTTP Server 2.2.25 for Windows

 Installing Apache HTTP Server 2.2.25 on Windows

 Publishing HTML Documents as Web Pages

 Starting and Stopping Apache Server

 Running Perl Scripts in "cgi-bin"

printenv.pl - Testing Perl CGI Environment

 500 Internal Server Error

 cgi-lib.pl - The Standard Library for CGI Scripts

 ReadParse() - Parsing Web Form Input Values

 Running Perl Scripts in "htdocs"

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB