You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Hans de Groot <ha...@dandy.nl> on 2006/11/10 21:01:11 UTC

Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Hi,

I would like to make my own vhost modules in modperl.

I tried some other modules but I cannot seem to get them to work or they do
not support enough options.

I want to put virtual host infomation in a mysql database so I can let my modules decide
what virtual host we need.

DocumentRoot
Servername
ServerAdmin
Customlog
ErrorLog
ServerAlias
ScriptAlias

And if possible the Directory directive and I would like to be able to configure
if this site can use php, embedded perl etc..

I have been searhing for days and been reading the "writing apache modules with perl and c" form O' reilly
but I am really stuck. I

I found several examples for changing the document root, but it does not work with my setup.
The examples nver seem to mention in what phase you need to do this.
I am guessing I need to change these things in the PerlPostReadRequestHandler phase.

This is what I have tried (just to change the document root)

#file:ModPerl/VHost.pm
#-------------------------
package ModPerl::VHost;
use Apache::Constants qw(OK DECLINED);
use strict;
sub handler {
 my $r = shift;
 my $old_docroot = $r->document_root;
  $r->document_root("/tmp");
  return OK;
 }
1;

But it returns (in the apache error log)

[error] [client 87.210.3.40] Usage: Apache::RequestRec::document_root(r) at /usr/lib/perl5/site_perl/ModPerl/VHost.pm line ....\n

It seems I can read but not write.

So my questions are:
Is it at all posible to do this with mod perl?
What phase should I use to change these directives?
Can anyone give me some example how to do this?

I do not need or like mod_vhost_alias or solutions like that and I need to do this on the fly, so when I add a new site to my
database it is online right away without restarting apache.

I think I am using mod_perl/1.99_16. Is that the same as mod_perl 2.x? or is it still mod_perl 1.x?
I use apache Apache/2.0.52

Any help would be apreciated.

Regards,

Hans de Groot




I can change the error_log for a virtual host but how to change the access_log?

Posted by Hans de Groot <ha...@dandy.nl>.
Hi,

I can use 
	$old_error_fname = $s->error_fname($result{error_log}); 
To set the location of the error log of a particular virtual host.

But I can't find a way to set the location of the normal access_log file.
this seems weird to me.

Does anyone no how to change that?

Thanks

Hans de Groot


--- 
Hans de Groot 
Email: hansg@dandy.nl   www: http://www.dandy.nl


Re: Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Posted by to...@tuxteam.de.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Nov 13, 2006 at 11:04:13PM +0100, Hans de Groot wrote:
> Hi,
> 
> I have been looking at the perl sections part.

[...]

> But would a reload of the httpd.conf kill the open sessions of visitors
> of the website? I always asumed it would but maybe I am wrong here. 

If you stop Aache *gracefully* (which I would assume happens in a
reload), it'll keep the open connections (the children with open
connections die after closing).

Whatever happens to the sessions depends on what your notion of session
is and how you manage it (if "session" to you is what it means around
here, you'll keep relevant data in persistent storage, typically
server-side and the client keeps a token for it (e.g. URL part, cookie,
hidden form field). So there is no need for it to die, even when completely
stopping and re-starting Apache).

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFWVmaBcgs9XrR2kYRAkZWAJ9zbzFgtOc/qgZXzOdVL6UU7AkxtgCeLvjE
DMfb+30nu6uZ74MgwMo2SqM=
=kbA8
-----END PGP SIGNATURE-----


Re: Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Posted by Hans de Groot <ha...@dandy.nl>.
Hi,

I have been looking at the perl sections part.

But as far as I can tell it's just a replacement for http.conf. I think
it still means I need top restart/reload the httpd.conf

The whole reason I want to do it on the fly is to prevent this. But
please tell me I am wrong in this ?

I tried to play with Apache2::Directive::conftree();

I manged to get a hash with data about thge virtual host I like to
change but altering this does not have any effect.

I have been tring to change many things but so far the only thing I can
give a new value is $r->document_root()

The rest seems only read only values. (like options etc).

I have a virtual host entry that us really empty:

<VirtualHost 81.24.48.204:80>
    ServerAdmin webmaster@webmaster.nl
    DocumentRoot /online/default/www/default/html
    ServerName www.default.nl
</VirtualHost>

I can now change the documentRoot on the fly, and I would like to be
able to change other things to like:

AddType application/x-httpd-php .php

To enable php for this site if this site needs it.

And also 

<Directory "/online/default/www/default/html2/">
            Options Indexes FollowSymLinks
            AllowOverride AuthConfig
                Order allow,deny
        Allow from all
 </Directory>


But I am really stuck here. I am at the point of giving up and combining
the Documentroot part with a generated .htaccess file placed in the
documentroot. 

The thing here is that I do not like my customers to be able to upload
their own .htaccess file. And so far I did not find away around this. 

So if anyone can give any example how to change more than just the
document root , I would be gratefull.

Maybe an offtopic question, 

But would a reload of the httpd.conf kill the open sessions of visitors
of the website? I always asumed it would but maybe I am wrong here. 

Regards

Hans de Groot




--- 
Hans de Groot 
Email: hansg@dandy.nl   www: http://www.dandy.nl


Re: Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Posted by Frank Wiles <fr...@wiles.org>.
On Fri, 10 Nov 2006 18:34:18 -0500
Jonathan Vanasco <mo...@2xlp.com> wrote:

> 
> On Nov 10, 2006, at 3:01 PM, Hans de Groot wrote:
> 
> > Hi,
> >
> > I would like to make my own vhost modules in modperl.
> 
> I would not do that at all.  because of the way mp handles memory
> and namespaces, vhosting mod_perl is a nightmare waiting to happen.
> 
> mp is really best used in dedicated server situations.
> 
> you could use something lightweight like lighttpd or nginx to handle  
> mass vhosting and then proxy that off to modperl enabled apache.
> 
> or write a vhost proxy in modperl that proxies off to other
> apaches. but running a vhost service and perl handlers/scripts under
> modperl will be a memory & resource nightmare.

   Trying to use mod_perl to speed up the vhosts' CGIs is a nightmare,
   but just using mod_perl to do your Apache configuration and having
   normal CGI Perls running under it causes no real pain other than
   the memory overhead of mp itself. 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------


Re: Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Nov 10, 2006, at 3:01 PM, Hans de Groot wrote:

> Hi,
>
> I would like to make my own vhost modules in modperl.

I would not do that at all.  because of the way mp handles memory and  
namespaces, vhosting mod_perl is a nightmare waiting to happen.

mp is really best used in dedicated server situations.

you could use something lightweight like lighttpd or nginx to handle  
mass vhosting and then proxy that off to modperl enabled apache.

or write a vhost proxy in modperl that proxies off to other apaches.   
but running a vhost service and perl handlers/scripts under modperl  
will be a memory & resource nightmare.

// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -



Re: Can't locate Apache2/compat.pm

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Nov 10, 2006, at 6:10 PM, Hans de Groot wrote:

> I am using mod_perl 1.99_16 (it's the one that came with centos 4.3)
>
> It seems that this is mod_perl 2.

uninstall it immediately, and install 2.0x -- whatever is current.

There was a giant a API change early on in the 2.0 cycle.  The docs  
reflect the new api namespaces, not the deprecated stuff you have.

That should solve a lot of your problems.



// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -



Can't locate Apache2/compat.pm

Posted by Hans de Groot <ha...@dandy.nl>.
Hello,

Okay maybe I should start with some thing more basic like figuring out
what mod_perl I am really using?.

I am using mod_perl 1.99_16 (it's the one that came with centos 4.3)

It seems that this is mod_perl 2.

I am reading the documentation at http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache_E_gt_request_

They mention Apache2::compat and other Apache2::* that I do not have
like 

use Apache2::RequestUtil ();

I get this message Can't locate Apache2/RequestUtil.pm in @INC...

And a locate for RequestUtil.pm results in only this answer
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi/Apache/RequestUtil.pm

So can some one explain what I am doing wrong? I though I have mod_perl
2 and not mod_perl 1. But why am I missing those Apache2 .pm files? 

I have a feeling I am in between versions? But Embedded perl works fine,
and it uses mod perl.  But I can't get any example to work properly. 

I hope some one can shed some light on this.

Regards

Hans de Groot




Re: Mod_perl and (mass) virtual hosting or a mod_vhost alternative

Posted by Frank Wiles <fr...@wiles.org>.
On Fri, 10 Nov 2006 21:01:11 +0100
Hans de Groot <ha...@dandy.nl> wrote:

> So my questions are:
> Is it at all posible to do this with mod perl?
> What phase should I use to change these directives?
> Can anyone give me some example how to do this?

   Yes it's possible to do with mod_perl, and in fact I think it's one
   of the strong points of mod_perl to be able to reconfigure Apache
   on the fly.  

   For examples of how to do this with mod_perl 2.x a good place
   to start is: 
 
   http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.html
    
> I think I am using mod_perl/1.99_16. Is that the same as mod_perl
> 2.x? or is it still mod_perl 1.x? I use apache Apache/2.0.52
> 
> Any help would be apreciated.

   Actually what you're using is a pre-release candidate of mod_perl
   2.x.  You're going to want to upgrade to the latest stable mod_perl
   from source as the version you are trying to use isn't really
   supported and will most likely cause you problems down the road. 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------