To Be GNU/Hurd
Tue, 10 Jun 2008
automatic per-user multiple-site setup on apache2
<Perl>
my $basepath = '/home/';
my $vhosts = '/sites/';
my $logs = '/logs/apache2/';
opendir my $users, $basepath;
my @users = readdir $users;
for my $user (@users) {
next if $user =~ /^\./;
next if ! -d $basepath . $user . $vhosts;
opendir my $sites, $basepath . $user . $vhosts;
my @sites = readdir $sites;
close $sites;
for my $site ( @sites ) {
next if $site =~ /^\./;
push @{ $VirtualHost{ '*' } }, {
ServerName => $site,
ServerAlias => "www.$site",
DocumentRoot => $basepath . $user . $vhosts . $site,
ErrorLog => $basepath . $user . $logs . "$site-error.log",
CustomLog => $basepath . $user . $logs . "$site-access.log combined",
};
}
}
</Perl>
I keep this in /etc/apache/sites-enabled/usersites. Users create sites by creating a directory of the format: /home/$username/sites/$domain/htdocs/. The only problem is that apache requires a restart each time one adds a new site.
Comments