Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm looking at using a Perl module to dynamically set up some virtual hosts at run-time.

mod_perl is what I'm looking at, of course, and PerlMapToStorageHandler seems like just about what I want. I can look up the user information in the database based on $r->hostname(), find their home directory, then call $r->filename($new_path) to set up the mapping. If I can get this to work, I'll cache the results, so I won't have to hit the database very often.

But, that method doesn't seem to work like I expect it to. Just to test, I wrote this sub, which should cause all requests to return test.txt:

sub handler { my $r = shift; my $newfn = "/var/www/test.txt"; warn "In PerlMapToStorageHandler Handler, hostname " . $r->hostnam +e() . ", uri " . $r->uri() . ", filename " . $r->filename() . ", new filename $newfn\n"; $r->filename($newfn); return Apache2::Const::OK; }
Instead, I get this in the error log:
In PerlMapToStorageHandler Handler, hostname, uri /, f +ilename /var/www/, new filename /var/www/test.txt [Sun Oct 11 22:12:38 2009] [error] [client] File does n +ot exist: /var/www/test.txt
and a 404 error in the browser.

The background is I'm working on a clustered environment with virtual hosts that are added from a Web interface. I'd like to be able to set up new virtual hosts by adding to the database and having Apache pick them up automatically, without the Web interface script having to arrange for the cluster of Web servers to be restarted. If somebody has a better idea for solving this problem, please let me know.


Updates: A few things other Monks have asked below that I should have included in the original.

  • This is on an up-to-date Debian Lenny, with Apache 2.2.9, mod_perl 2.0.4, and Perl 5.10.0.
  • It's a Debian default setup, no chroot jail, etc.
  • File /var/www/test.txt exists and is readable by the Web server. If I change Apache's configuration to use /var/www as its DocumentRoot, the file shows up.

In reply to mod_perl PerlMapToStorageHandler by sgifford

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2018-06-19 22:53 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (115 votes). Check out past polls.