Save this script in the /home/httpd/perl/mod_perl_rules1.pl file. Notice
that the shebang line is not needed with mod_perl, but you can keep it if you want. So the following script can be used as well:
Of course you can write the same script using the Apache Perl API:
my $r = shift;
Save this script in the /home/httpd/perl/mod_perl_rules2.pl file.
Now make both of the scripts executable and readable by the server. Remember that when you execute scripts from a shell, they are being executed by the user-name you are logged with. When instead you try to run the scripts by issuing requests, Apache needs to be able to read and execute them. So we make the script readable and executable by everybody:
If you don't want other users to be able to read your script, you should
add yourself into the groupname the webserver is running with (as defined by the Group directive) and then make the script owned by that group and then you can tighten the permissions. For example on my machine I run the server under the group httpd and I'm the only one who is in the same group, so I can do the following:
The localhost approach will work only if the browser is running on the same machine as the server. If not--use the real server name for this test, for example:
If there is any problem please refer to the error_log file for the error reports.
Now it's a time to move your CGI scripts from /somewhere/cgi-bin directory to /home/httpd/perl/ and see them running much much faster, when requested from the newly configured base URL (/perl/). If you were accessing the script as /cgi-bin/test.pl, it will now be accessed from /perl/test.pl.
Some of your scripts might not work immediately and will require some minor tweaking or even a partial rewrite to work properly with mod_perl. Chances are that if you are not practicing sloppy programming, the scripts will work without any modifications at all.
If you have a problem with your scripts, a good approach is to replace Apache::Registry with Apache::PerlRun in httpd.conf, as the latter can execute really badly written scripts. Put the following configuration directives instead in httpd.conf and restart the server:
allow from all
Now your scripts should work for sure, unless there is something in them
mod_perl doesn't accept. We will discuss these nuances in future articles.