First, make a directory for mod_perl programs. This directory can be anywhere , except that it's a bad idea to put it in the Apache document tree starting with /var/www/html for the same reasons that it is a bad idea to do so for CGI programs. Let's choose /var/www/mod_perl . Create the directory with the appropriate permissions: # mkdir /var/www/mod_perl # chmod a+rx /var/www/mod_perl Apache needs to be configured appropriately to use mod_perl effectively. We start by creating a Perl script that Apache runs each time it starts up (or more precisely, each time the Apache configuration file is reread). Name this program startup.pl , since it runs when Apache starts up, and put it in the Apache configuration directory /etc/httpd/conf : #! /usr/bin/perl # tell Perl where to find our modules use lib /var/www/mod_perl; # use some common modules use Apache::Registry(); use Apache::Constants(); use CGI :standard; use DBI; # add other modules here... # the file needs to end with 1; 1; The use lib statement tells Apache (really Perl that is built into Apache) where to find the mod_perl modules that we will write ”in this case, the newly minted /var/www/mod_perl directory. The next four use statements preload four commonly used Perl modules. Preloading at server start-up speeds up loading the individual modules when they are used in the mod_perl programs [1] ”if this start-up script weren't used, the modules would have to be loaded the first time each mod_perl program executed, while the client waited for a response from the server.
The last line must be 1; ” strange , but important. This program, and all Perl modules, must end in 1; so that when they are used via the use pragma ( use CGI; ), the use must evaluate to 1 (true). To accomplish that, simply make the last line of the module 1; . This needs to be done for all the mod_perl modules. Then configure Apache to execute the start-up script by adding these lines at the end of the Apache configuration file /etc/httpd/conf/httpd. conf : PerlRequire conf/startup.pl PerlFreshRestart On Restart Apache to test the start-up script: # /etc/init.d/httpd graceful and check the log file for error messages: # tail -f /var/log/httpd/error_log If you see no errors, all is well with the start-up script. |