Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Using ModPerl::Registry without root

by dmorgo (Pilgrim)
on May 22, 2004 at 21:26 UTC ( #355625=perltutorial: print w/replies, xml ) Need Help??

ModPerl::Registry is the mod_perl2 version of Apache::Registry. This is not intended to be a complete mod_perl tutorial, but is more of a recipe that shows how to get a simple mod_perl2 script up and running on a server that meets the following conditions:

  1. The system has mod_perl2 installed and already configured in the httpd.conf file.
  2. You do not have write access to httpd.conf, and might not even be able to convine the admins to make changes for you.
  3. You do not have write access to the main perl or cgi-perl directory configured as the httpd server's directory for mod_perl scripts.
  4. The system is configured to give you the ability to use an .htaccess file in your web document directory (i.e., ~/public_html) to change your own configuration.
(Why would anyone use a hosting account without httpd.conf write access? Cost. For $10/month, the hosting company I use does provide mod_perl2, but does not provide support for it. This recipe shows how to get started on such an account.)

For the pedantic, a more technically correct title for this node might be "Using ModPerl::Registry when you don't have an account that has or are not in a group that has write access to httpd.conf, and can't convince the sysadmin to edit it, and can't change hosts, and..." but I think "Using ModPerl::Registry without root", while less accurate, is a snappier title.

This has been tested with mod_perl 1.99_09. YMMV.

First, check the httpd.conf setup. The file is often in a directory like /usr/local/apache/conf. It should contain something like this:

LoadModule perl_module modules/ # ... <IfModule mod_perl.c> <Location /perl> #AllowOverride None SetHandler perl-script PerlHandler ModPerl::Registry Options ExecCGI allow from all PerlSendHeader On </Location> # the next part is not required for this recipe to work <Location /cgi-perl> #AllowOverride None SetHandler perl-script PerlHandler ModPerl::PerlRun Options ExecCGI allow from all PerlOptions +ParseHeaders </Location> </IfModule>
Then you need three more files:

1. ~/public_html/.htaccess, containing these lines:

<FilesMatch ""> SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI PerlSendHeader on </FilesMatch>
2. ~/public_html/, containing this:

(The following example is adapted from the example in Stas Bekman's tutorial "Getting Started With mod_perl".)

package TestModPerl; my $total = 0; my $counter = 0; sub run { $counter = 0; for (1 .. 5) { increment_counter(); } } sub increment_counter { $counter++; print "Counter is equal to $counter!<br>\n"; } sub total { $total++; print "This has run $total times.<br>\n"; } 1; __END__ # apparently in mod_perl2 having __END__ is OK.
3. ~/public_html/, containing this:
#!/usr/bin/perl BEGIN { push @INC, "/home/YOURACCOUNTNAMEHERE/public_html"; } use strict; use TestModPerl; print "Content-type: text/html\n\n"; TestModPerl::run(); TestModPerl::total();
Now access the URL for your script to see the result:

If things are working as intended, you will see the count go from one to five with each invocation (as you hit refresh) and you will see the total climb incrementally across invocations. So after three invocations it will look like this:

Counter is equal to 1!
Counter is equal to 2!
Counter is equal to 3!
Counter is equal to 4!
Counter is equal to 5!
This has run 3 times.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://355625]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2022-05-16 15:13 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (63 votes). Check out past polls.