You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by sk...@lists.randomfx.net on 2002/08/05 22:56:13 UTC

Generating vhost config dynamically with DBI ?

Hi,

	Is there a way to have apache dynamically fetch the vhost config
from an SQL database?  I would like to avoid restarting apache as I may be
adding/deleting many vhosts each day.

	I know I can generate apache configs using mod_perl but i need to
restart apache to get these changes seen.

	Any hope for me?

	Regards,

--
Sean Kelly


Re: Generating vhost config dynamically with DBI ?

Posted by Stas Bekman <st...@stason.org>.
sk@lists.randomfx.net wrote:
> Hi,
> 
> 	Is there a way to have apache dynamically fetch the vhost config
> from an SQL database?  I would like to avoid restarting apache as I may be
> adding/deleting many vhosts each day.
> 
> 	I know I can generate apache configs using mod_perl but i need to
> restart apache to get these changes seen.
> 
> 	Any hope for me?

no hope. This is an Apache issue. You cannot change configuration at run 
time.



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Generating vhost config dynamically with DBI ?

Posted by Mathieu <jo...@club-internet.fr>.
sk@lists.randomfx.net wrote:

> Hi,
>
>         Is there a way to have apache dynamically fetch the vhost config
> from an SQL database?  I would like to avoid restarting apache as I may be
> adding/deleting many vhosts each day.
>
>         I know I can generate apache configs using mod_perl but i need to
> restart apache to get these changes seen.
>
>         Any hope for me?
>
>         Regards,
>
> --
> Sean Kelly

Hi,
    some weeks ago I posted to have ideas on the same problem.
For now I found two solutions :
    - use perl sections in the httpd.conf and fetch data from the database,
then use a PerlChildInitHandler to refresh the vhost lists.
    - use one vh which will intercept all requests for requested
virtualhosts.

For the first solution I manage to add vhost on the fly but cannot find the
way to delete them and have the configuration refreshed.
I didn't went too deep in the problem but I couldn't managed to update my
configuration and as I'm not very familiar with mod_perl
hacking I just dropped the idea for another one.

The second solution is the one I'm actually working on for a project. I only
have one virtual host declared in my apache configuration.
Say :
<VirtualHost _default_>
  ServerName www.dynvh.com
   ErrorLog ..
   CustomLog ...
  SetHandler perl-script
  <Location "/">
    PerlHandler MainHandler
  </Location>
</VirtualHost>

All the dynamic virtual host that I want to manage point to the Ip of this
virtual host.
So all the work is going to be done by the MainHandler that will analyse the
client request.

This is for the client part.
On the other side, I have an administration interface that permits me to
declare domains, sub-domains, domain alias, subdomain aliases,
which are stored in a database. Based on the information stored in the
database I generate a structure a bit like the one generated through
the perl-sections, with all the domains, subdomains, aliases, etc ... This
cached structure being accessible by the MainHandler.

So when a client request  www.mydynvh1.com, the request is going to be taken
care of by MainHandler which knows through the
cache structure the declared vhost on the system. The vhost requested by the
client can be retrieved through the $r->hostname (which
checks the $r->header_in('Host') of the client, its the following format
www.mydynvh1.com and if the port is specified www.mydynvh1.com:8080).

So now if the vh is declared I can process the rest of the request through
other handlers or redirect the client to an error page.

I prefer the second solution as from what I want to do I have more control on
all the processing and I didn't manage to do what I wanted
with the first solution. Maybe there are other ones which I'm not aware of,
but be glad to here of.

I hope this will help you, I will really appreciate any critiques and
feedback on my solution and what can be ameliorated.

Regards,
    Mathieu



Re: Generating vhost config dynamically with DBI ?

Posted by Drew Schatt <sc...@schatt.com>.
You might want to look into using the vhost directory, in which apache
looks in a single directory for folders named after the different hosts.
It seems to work pretty well, and it works without a restart.
	-Drew Schatt

On Mon, 5 Aug 2002 sk@lists.randomfx.net wrote:

> Hi,
>
> 	Is there a way to have apache dynamically fetch the vhost config
> from an SQL database?  I would like to avoid restarting apache as I may be
> adding/deleting many vhosts each day.
>
> 	I know I can generate apache configs using mod_perl but i need to
> restart apache to get these changes seen.
>
> 	Any hope for me?
>
> 	Regards,
>
> --
> Sean Kelly
>
>