Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: 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.

In reply to Using ModPerl::Registry without root by dmorgo

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-05-24 15:05 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.