Electric Type

Multimedia

About Us

News

Help

Intro to Mod_Perl

Page 6 — Parsing CGI Scripts with Apache

By itself, mod_perl has no idea what a CGI script is or how to run one. Luckily, mod_perl ships with software that does: Apache::Registry. This Perl script is actually a HTTP request handler and it knows how to convert existing CGI scripts into something mod_perl understands.

The first thing we need to do is add a few lines to our httpd.conf file. For this example, let's parse all files in a directory called mod-perl.

Alias /mod-perl /home/httpd/mod-perl
This directive tells apache that any request for /mod-perl should be made to the /home/httpd/mod-perl directory. By defining a new location for CGI scripts, you separate the scripts served from mod_perl from your existing cgi-scripts, which helps keep things nice and organized. Next, let's tell Apache how to serve all requests to /mod_perl:
<Location /mod-perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
These directives instruct Apache to use the Apache::Registry script for all requests in /mod-perl. If you were to examine the Apache::Registry file (which is usually found in your site_perl directory, often /usr/lib/perl5/site_perl/), you'd find that Apache::Registry is written as a module with a subroutine called handler. When Apache runs, it loads the Apache::Registry and calls the "handler" subroutine. And this subroutine compiles and runs your CGI script.

At this point, you should be able to make CGI requests from /mod-perl. Go ahead and try it by placing a copy of the script in both /cgi-bin and /mod-perl. Check your script by running the script a few times from your browser to make sure the value of customers is correct.

Now let's see what else mod_perl can do for us.

next page»


Dynamic HTML  

Frames  

HTML Basics  

Stylesheets  

Tables  

XML  

Javascript  

Database Connections  

Intro To Perl  

HTML 4.0  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.