Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This script supposedly should take * out of *, assign it to $subdomain variable, and $subdomain should be put to AssignUserId.

However, no matter how hard I try, I can't get this to work. I've been working on this for days, and am really desperate. If you think this is a lot of work, please charge me consultancy and come get the root passwd.

Any ideas though? Thanks...

 Use Apache2::ServerRec qw//; 
 use Apache2::ServerUtil qw//; 
 use Apache2::RequestRec qw//; 
 use Apache2::RequestUtil qw//; 
 use Apache2::Const qw/OK DECLINED/; 

 my $s = Apache2::ServerUtil->server; 

 $s->push_handlers(PerlHeaderParserHandler => sub { my($r) = @_; 
 if ( $r->hostname =~ m/(.*)\.([^.]+\.\w+)$/ ) { 
 my($subdomain,$domain) = ($1,$2); 

 # -----------
 # if requested domain is,
 # this successfully assigns ServerAdmin
 # so gathering domain parts working


 # --------------
 # this is supposed to insert this line inside Virtual host
 # --------------
 # <IfModule mpm_itk_module> AssignUserId fio domain</IfModule>
 # --------------

 $r->add_config([ "<IfModule mpm_itk_module>", 
 "AssignUserId $subdomain $domain", 

 if ( $@ ) { warn $@ } 

 return OK; 

 } else { 
 return DECLINED; 
share|improve this question
Have you placed this &lt;Perl&gt; block inside the top-level configuration? Inside a virtual server configuration? Inside a .htaccess file? – PP. Nov 22 '09 at 23:55
up vote 1 down vote accepted

My initial guess here is that you have set up a handler via the hook PerlHeaderParserHandler to which you have been handed $r, or the request object.

From the documentation for AssignUserId (the parameter you want to dynamically configure) the context of configuration must be virtual-host. At a guess I would suspect this to mean you should configure on a per-server basis rather than on a per-request basis.

See $s->add_config documentation as opposed to $r->add_config.

Depend on the processing of directives it is possible that by the time the request hook has been called the processing of AssignUserId has already taken place in which case there's not a lot you can do besides statically configuring each subdomain as a virtual server..

update 1: of course if you try and use $s->add_config for every request you run the danger of having an unwieldy server configuration in memory with the same directive repeated over and over. Making updating the server configuration every request impractical.

Perhaps it is still possible to do this with $r->add_config(), noting from the documentation that "Configuration directives are processed as if given in a <Location> block". Have you tried a non-Perl test of placing the AssignUserId parameter in a <Location> block?

share|improve this answer
Hi PP, I placed this inside a virtual host that catches every possible domain * AssignUserId is an internal part of mpm-itk so I don't think placing in Location wouldn't work. If you meant that if I have tried to insert Location just to see if it works, it's a good idea. Notes: I didn't get the danger you mentioned on your update 1. – Devrim Nov 23 '09 at 2:58
Apache uses memory pools that simply grow until released. The request object ($r) is allocated at the beginning of processing every single web page request, then released after processing that web page request. So you can add as much as you like to it because that memory will be released after the request. The server object ($s), however, gets allocated when the server process starts up, and doesn't get released until the process dies. So you want to add to that configuration once, not every request. – PP. Nov 23 '09 at 8:01
If you believe AssignUserId cannot be placed inside a <Location> directive then you cannot use $r->add_config() according to the documentation. – PP. Nov 23 '09 at 8:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.