This question springs from a recent conversation I had with btrott and his rather excellent STAMP script.

Imagine if you will a typical Apache box, it's got one shared CGI-BIN, or mod_perl folder that is shared by all the various virtual domains on the box. Each domain looks different, so I want to make the script look different too.

QUESTION how do you neatly configure the script for all the various domains?

You can ask CGI to give you the virtual host name, and then check to see if there is a configuration file for it, if not you read a default one. This is what I tried, see code below. It works okay, but you'll end up with a folder full of config files, one per script per host, which may get messy.

So my question is, how do you neatly write CGI/mod_Perl script so that they can be shared on a mass-hosting Apache box, and yet maintain their own look'n'feel (via config), and what have you.

my $server = "localhost"; # Default host my $domain = ".company.com"; # Default domain my $conf_loc = "/someplace"; # Where config files live $server = $q->virtual_host() if $q->virtual_host(); # Where are +we? $server .= $domain unless ($server =~ /[$domain]$/i); # Need a do +main? if ($server =~ /^([-\w\.]+)$/) { # clean it $server = lc($1); chdir $conf_loc or error($q, qq(Unable to locate configuration fol +der $conf_loc)); $CFG_FILE = $server . ".$CFG_FILE" if ($server && -R "$server.$CFG +_FILE"); # If there is a specific file then use it }

$CFG_FILE is what STAMP expects to use, and error is it's error handling routine.

This is an addition to STAMP, I used for ilustration purposes. STAMP is cool, get it your self from it's author.

As ever thanks in advance.


In reply to Running Perl scripts from a single CGI-BIN, on a multiple-virtual hosting server by ajt

Title:
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, details, 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, summary, 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.