Configuring Apache
Server and Perl for CGI
T.A. Maisa Khudair
Dr. Qusai Abu Ein
Setting up Apache for Windows
Install Apache Server from following web
site:
http://httpd.apache.org/download.cgi
Choose the Win32 Binary (MSI Installer):
apache_2.2.4-win32-x86-no_ssl.msi
To start using CGI, you have to download
ActivePerl from following web site:
http://www.ricocheting.com/server/cgi.html
Cont’d
Get the Windows (x86) MSI version
To activate CGI in Perl, use your Notepad
Editor
open E:\Apache2_2\conf\httpd.conf
(note: Path in PINK is the path you had
installed your ActivePerl to in your
computer)
search for Options Indexes
FollowSymLinks
Cont’d
when you find it add ExecCGI to the end
so it looks like Options Indexes
FollowSymLinks ExecCGI
Always keep writing this line at the
beginning of your CGI file:
#!E:/Perl/bin/perl.exe
To start using Apache Server, go to Start
Menu, search for Apache Http Server, then
Control Apache Server > Start
Testing Apache Server
To test your Apache Server working, go to
your browser web page, type in the
address bar the following:
http://localhost
If you got a message telling you:
It works! Your server is working well.
Writing CGI Scripts
In order to execute your CGI scripts, you
have to put them in cgi-bin folder
located in your Apache Directory in your
PC
Your files should be saved like this:
fileName.cgi
To run your CGI, type:
http://localhost/cgi-bin/fileName.cgi.
First CGI Example
#!d:/Perl/bin/perl.exe
print "Content-type: text/html\n\n";
print "Hello, World.";
print "This is ME!!";
Output
Hello, World
This is ME!!
Cont’d :Environment variables
example
#!d:/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";
}
Output
DOCUMENT_ROOT = /usr/local/etc/apache/htdocs
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
HTTP_ACCEPT_CHARSET = iso-8859-1,*,utf-8
HTTP_ACCEPT_LANGUAGE = en
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = 200.210.220.1:8080
HTTP_USER_AGENT = Mozilla/4.01 [en] (Win95; I)
PATH = /usr/local/bin:/bin:/etc:/usr/bin
QUERY_STRING =
REMOTE_ADDR = 200.210.220.3
REMOTE_HOST = 200.210.220.3
REMOTE_PORT = 1029
REQUEST_METHOD = GET
REQUEST_URI = /cgi-bin/utils/printenv.cgi
SCRIPT_FILENAME = /usr/local/lib/apache/cgi-bin/utils/printenv.cgi
SCRIPT_NAME = /cgi-bin/utils/printenv.cgi
SERVER_ADMIN = adminguy@acme.com
SERVER_NAME = coyote.acme.com
SERVER_PORT = 8080
SERVER_PROTOCOL = HTTP/1.0
SERVER_SOFTWARE = Apache/1.2.5
TZ = :US/Eastern
Any Questions??