Author |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Fri 29 Sep '06 16:53 Post subject: |
|
|
Well hosting companies do'nt give out there in the house modules.
But should be to hard to make one if you base it off the existing Apache modules there OS. |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Fri 29 Sep '06 18:13 Post subject: |
|
|
If I do end up creating one, I'll keep it open source. I'll have to look over the code this weekend.
But, you say it 'should be hard' or 'shouldn't be hard'? Because, to me, I think it would be easier to create one based of the current apache module. |
|
Back to top |
|
DeliriumServers
Joined: 17 Jun 2006 Posts: 54 Location: H Town
|
Posted: Fri 29 Sep '06 23:03 Post subject: |
|
|
I think that if you added the basedir option to mod_vd, it would be the perfect solution.. no restarting, automatic domain and sub domain creation, and faster than all the other virtual hosting modules...
I'm not sure you're allowed to redistribute modifications according to the licence.... but it might be worth asking the creator, he might even include it in his version if you did, otherwise I don't believe he works on the module anymore
-delirium |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Sat 30 Sep '06 0:22 Post subject: |
|
|
Eep, your right :S Thanks, and i'll be checking out this mod_vd
THanks |
|
Back to top |
|
DeliriumServers
Joined: 17 Jun 2006 Posts: 54 Location: H Town
|
Posted: Sat 07 Oct '06 23:46 Post subject: |
|
|
hey, just wondering if you came up with anything/ figured out how to mod mod_vd
-delirium |
|
Back to top |
|
bokehman

Joined: 12 Oct 2006 Posts: 11
|
Posted: Thu 12 Oct '06 1:23 Post subject: |
|
|
AMailer wrote: | Hence, is there a way that I can get around doing that? Do professional web hosts restart their apache server after every new domai is added? | A restart is not needed to add domains. That is the whole point of a dynamic virtual host. |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Thu 12 Oct '06 1:32 Post subject: |
|
|
Yes but with these setups you do need to restart (at least the configs)
And DeliriumServers, I haven't had a chance of even installing the mod_vd, I'll try to do that this weekend and will post the results. |
|
Back to top |
|
bokehman

Joined: 12 Oct 2006 Posts: 11
|
Posted: Thu 12 Oct '06 10:29 Post subject: |
|
|
There are a few third party modules floating around. The problem with dynamic vhosts is the loss of certain PHP variables but these modules sort that out and without the restart. With them it is possible to write the configuration for virtual hosts into a MySQL table instead of in the vhost and the table contains all the php values relevant to that domain. This allows domains to be added by altering the SQL table rather than restarting the server. |
|
Back to top |
|
DeliriumServers
Joined: 17 Jun 2006 Posts: 54 Location: H Town
|
Posted: Thu 12 Oct '06 20:49 Post subject: |
|
|
@bokehman well if you could point out a dynamic vhost module that runs on windows apache, and supports php variables, we'd appreciate it. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Thu 12 Oct '06 21:01 Post subject: |
|
|
Well the way i do it it do a -k restart no request get dropped. Since it keeps listening while the conf is reread and then just contineus. Port 80 isn't even released from the process |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Thu 12 Oct '06 21:17 Post subject: |
|
|
I heard about the SQL module that can do that, but the speed of retrieveing the domain slows down a bit, especailly if your MySQL server is on the same server as the apache server - at least this is what I think.
Though are you suggestion that most webhosts use that module? Or do they just build their own?
Also Jorge, when you run the httpd -k restart command, do you run it manually or have you written a script to run it when ever you add something to your vhost config file? If its a script, how did you get it to runt he command? It requires root access at least. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Thu 12 Oct '06 23:18 Post subject: |
|
|
AMailer wrote: | I heard about the SQL module that can do that, but the speed of retrieveing the domain slows down a bit, especailly if your MySQL server is on the same server as the apache server - at least this is what I think.
Though are you suggestion that most webhosts use that module? Or do they just build their own?
Also Jorge, when you run the httpd -k restart command, do you run it manually or have you written a script to run it when ever you add something to your vhost config file? If its a script, how did you get it to runt he command? It requires root access at least. |
I wrote my own scrip that updatres host.conf (special config) I just ssh over to the machine, then run sudo host_manage.pl
and nabigate through the menu it will handle all the restarts folder deletion creation, simple conf changes (like who has php enable etc) for me |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Fri 13 Oct '06 2:26 Post subject: |
|
|
I see, SSH to your server, thanks.
Anyhow for that MySQL Module check this out:
http://pookey.co.uk/wiki/linux/shapvh
Not sure if you can use the open_basedir restriction here |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7402 Location: EU, Germany, Next to Hamburg
|
Posted: Fri 13 Oct '06 9:18 Post subject: |
|
|
In the FAQs from that page is written. that is a) *nix system code b) it do NOT support apache 2.0 yet only 1.3.x
So IMHO that is not a solution. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Fri 13 Oct '06 17:26 Post subject: |
|
|
For safety reasons i won't post my current version of my script but i can give you my older one.
Only difference here is that a httpd -k restart or a apachectl restart needs to be ran manually when your done with the host managing script.
This script is multi platform (tested on Windows, Mac OS X and Gentoo)
host_manager.pl
Code: | #/usr/bin/perl
use Switch;
use File::Copy;
# Configuration
###################
$host_path = "/hosts";
$host_conf = "/httpd-2.2/conf/hosts.conf";
$httpd_path = "/httpd-2.2/bin";
# Main Program
###################
sub header{
if(unixcompatible()){
system('clear');
}else{
system('cls');
}
print "#####################################\n";
print "# Virtual Host Manager #\n";
print "# By Jorge Schrauwen 2006 #\n";
print "#####################################\n";
}
sub unixcompatible{
$UNIX = `perl -v`;
if($UNIX=~m/(darwin|(li|u)n(i|u)x|\s*bsd\s)/i){
return 1;
}else{
return 0;
}
}
sub main{
print "1) Create Virtual Host\n";
print "2) Remove Virtual Host\n";
print "3) Change Virtual Host\n";
print "4) List Virtual Hosts\n\n";
print "0) Exit\n\n";
print "Select: ";
chomp($opt = <STDIN>);
switch ($opt){
case 1 { mkhost(); }
case 2 { rmhost(); }
case 3 { chhost(); }
case 4 { listhost(); }
case 0 { }
else { main(); }
}
}
sub mkhost{
header();
# get data
print "Create Host: ";
chomp($fqdn = <STDIN>);
print "DAV Username: ";
chomp($davuser = <STDIN>);
print "DAV Password: ";
chomp($davpass = <STDIN>);
header();
if(!-d "$host_path/$fqdn"){
print "Creating directories...\n";
mkdir("$host_path/$fqdn", 0777);
mkdir("$host_path/$fqdn/_server", 0777);
mkdir("$host_path/$fqdn/_server/logs", 0777);
mkdir("$host_path/$fqdn/_server/ssl", 0777);
mkdir("$host_path/$fqdn/httpdocs", 0777);
#mkdir("$host_path/$fqdn/httpsdocs", 0777);
mkdir("$host_path/$fqdn/cgi-bin", 0777);
print "Creating users.db...\n";
htpasswd('add', $davuser, $davpass, "$host_path/$fqdn/_server/users.db");
print "Updating configuration files...\n";
configure(1, 1, 1, "$host_path/$fqdn/_server/host_settings.conf");
updatehost(1, $fqdn);
print "Restarting httpd server...\n";
httpdmanage("restart");
$msg = "Successfully created $fqdn!\n\n";
}else{
$msg = "$fqdn allready exists!\n\n";
}
header();
print $msg;
main();
}
sub rmhost{
header();
print "Remove Host: ";
chomp($fqdn = <STDIN>);
if(-d "$host_path/$fqdn"){
print "Remove $fqdn and all its files? (y/N): ";
chomp($confirm = <STDIN>);
if(lc($confirm) eq "y"){
$confirm = 1;
}else{
$confirm = 0;
}
if($confirm){
print "Stopping httpd server...\n";
httpdmanage("stop");
print "Updating configuration files...\n";
updatehost(0, $fqdn);
print "Starting httpd server...\n";
httpdmanage("start");
print "Removing directories...\n";
rmdir_r("$host_path/$fqdn");
$msg = "Successfully removed $fqdn!\n\n";
}else{
$msg = '';
}
}else{
$msg = "$fqdn doesn't exists!\n\n";
}
header();
print $msg;
main();
}
sub chhost{
header();
print "Host Domain: ";
chomp($fqdn = <STDIN>);
if(-d "$host_path/$fqdn"){
chhost_menu($fqdn);
}else{
header();
print "$fqdn doesn't exists!\n\n";
main();
}
}
sub chhost_menu{
$fqdn=$_[0];
header();
print "1) Update Configuration\n";
print "2) Manage DAV Users\n\n";
print "0) Back\n\n";
print "Select: ";
chomp($opt = <STDIN>);
switch ($opt){
case 1 { chhost_config($fqdn); }
case 2 { chhost_dav_menu($fqdn); }
case 0 { header(); main(); }
else { chhost_menu($fqdn); }
}
}
sub chhost_config{
$fqdn=$_[0];
header();
# get data
print "Enable PHP (Y/n): ";
chomp($php = <STDIN>);
if(lc($php) eq "n"){
$php = 0;
}else{
$php = 1;
}
print "Enable Perl (Y/n): ";
chomp($perl = <STDIN>);
if(lc($perl) eq "n"){
$perl = 0;
}else{
$perl = 1;
}
print "Enable SSI (Y/n): ";
chomp($ssi = <STDIN>);
if(lc($ssi) eq "n"){
$ssi = 0;
}else{
$ssi = 1;
}
header();
print "Updating configuration files...\n";
$msg = configure($php, $perl, $ssi, "$host_path/$fqdn/_server/host_settings.conf");
print "Restarting httpd server...\n";
httpdmanage("restart");
header();
if($msg == 1){
print "$fqdn has been updated!\n\n";
}else{
print "$msg\n\n";
}
main();
}
sub chhost_dav_menu{
$fqdn=$_[0];
header();
print "1) Add/Update User\n";
print "2) Remove User\n";
print "3) List Users\n\n";
print "0) Back\n\n";
print "Select: ";
chomp($opt = <STDIN>);
switch ($opt){
case 1 { dav_add($fqdn); }
case 2 { dav_remove($fqdn); }
case 3 { dav_list($fqdn); }
case 0 { chhost_menu($fqdn); }
else { chhost_dav_menu($fqdn); }
}
}
sub dav_add{
$fqdn=$_[0];
header();
print "Username: ";
chomp($davuser = <STDIN>);
print "Password: ";
chomp($davpass = <STDIN>);
htpasswd('add', $davuser, $davpass, "$host_path/$fqdn/_server/users.db");
chhost_dav_menu($fqdn);
}
sub dav_remove{
$fqdn=$_[0];
header();
print "Username: ";
chomp($davuser = <STDIN>);
htpasswd('rm', $davuser, '', "$host_path/$fqdn/_server/users.db");
chhost_dav_menu($fqdn);
}
sub dav_list{
$fqdn=$_[0];
header();
open (USERFILE, "$host_path/$fqdn/_server/users.db");
$i = 0;
while ($uline = <USERFILE>) {
$i++;
@user = split(':', $uline);
print "$i. @user[0]\n";
}
close(USERFILE);
print "\nManage DAV Users>";
<STDIN>;
chhost_dav_menu($fqdn);
}
sub listhost{
$fqdn=$_[0];
header();
opendir(HDIR, $host_path);
$i = 0;
while (my $file = readdir(HDIR)) {
if(($file ne '.') and ($file ne '..')){
if(-d "$host_path/$file"){
$i++;
print "$i. $file\n";
}
}
}
closedir(HDIR);
print "\nManage Hosts>";
<STDIN>;
header();
main();
}
sub configure{
# get variables
$php=$_[0];
$perl=$_[1];
$ssi=$_[2];
$conf_path=$_[3];
# gen host_settings
open(HCONF,">$conf_path") or return 'Failed to open configuration file!';
if($ssi){
print HCONF "# SSI Configuration\n";
print HCONF "<IfModule mod_include.c>\n";
print HCONF "\tAddType text/html .shtml .shtm\n";
print HCONF "\tAddOutputFilter INCLUDES .shtml .shtm\n";
print HCONF "</IfModule>\n\n";
}
if($perl){
print HCONF "# CGI Configuration\n";
print HCONF "<IfModule mod_cgi.c>\n";
print HCONF "\tAddHandler cgi-script .cgi .pl\n";
print HCONF "</IfModule>\n";
print HCONF "<IfModule mod_cgid.c>\n";
print HCONF "\tAddHandler cgi-script .cgi .pl\n";
print HCONF "</IfModule>\n\n";
}
if($php){
print HCONF "# PHP Configuration\n";
print HCONF "<IfModule mod_php5.c>\n";
print HCONF "\tAddType application/x-httpd-php .php\n";
print HCONF "\tAddType application/x-httpd-php .phtml\n";
print HCONF "\tAddType application/x-httpd-php-source .phps\n";
print HCONF "</IfModule>\n\n";
}
close(HCONF);
}
sub updatehost{
# get variables
$action=$_[0];
$host=$_[1];
# edit hosts.conf
open (HOSTFILE, $host_conf) or die('Failed to open host file!');
open (HOSTFILE_NEW,">".$host_conf."_new");
if($action){
while ($hline = <HOSTFILE>) {
print HOSTFILE_NEW $hline;
}
print HOSTFILE_NEW "Use VirtualHost $host\n";
}else{
while ($hline = <HOSTFILE>) {
@chunks = split(' ', $hline);
if(lc(@chunks[0]) ne 'use'){
print HOSTFILE_NEW $hline;
}else{
$chost = lc(@chunks[2]);
chomp($chost);
if($chost ne $host){
print HOSTFILE_NEW $hline;
}
}
}
}
close(HOSTFILE);
close(HOSTFILE_NEW);
unlink("$host_conf");
move($host_conf."_new", "$host_conf");
}
sub htpasswd{
# get variables
$action=lc($_[0]);
$user=$_[1];
$pass=$_[2];
$htpassfile=$_[3];
# create users.db
$htpasswdcmd = "$httpd_path/htpasswd -";
if(!-e $htpassfile){ $htpasswdcmd .= "c"; }
if($action eq 'add'){
$htpasswdcmd .= "sb ".$htpassfile." ".$user." ".$pass;
}
if($action eq 'rm'){
$htpasswdcmd .= "D ".$htpassfile." ".$user;
}
system($htpasswdcmd);
}
sub httpdmanage{
if(-e "$httpd_path/apachectl"){
$httpdcmd = "$httpd_path/apachectl ";
}else{
$httpdcmd = "$httpd_path/httpd -k ";
}
$httpdcmd .= $_[0];
system($httpdcmd);
}
sub rmdir_r{
my $dir = shift;
local *DIR;
opendir DIR, $dir or die "opendir $dir: $!";
my $found = 0;
while ($_ = readdir DIR) {
next if /^\.{1,2}$/;
my $path = "$dir/$_";
unlink $path if -f $path;
rmdir_r($path) if -d $path;
}
closedir DIR;
rmdir $dir or print "error - $!";
}
# init
###################
header();
main();
|
Edit
Quote: | $host_path = "/hosts";
$host_conf = "/httpd-2.2/conf/hosts.conf";
$httpd_path = "/httpd-2.2/bin";
|
to match your host.cong
host.conf
Code: |
############################
# Host Settings #
############################
# Required Modules
LoadModule macro_module modules/mod_macro.so
<IfDefine DAV>
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
DAVLockDB logs/davlock
</IfDefine>
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex default
</IfDefine>
# Listening Sockets
Listen 80
<IfDefine DAV>
Listen 81
</IfDefine>
<IfDefine SSL>
Listen 443
</IfDefine>
# VirtualHost Macro
NameVirtualHost *:80
NameVirtualHost *:81
NameVirtualHost *:443
<Macro VirtualHost $host>
# HTTP Server
<VirtualHost *:80>
ServerName $host:80
ErrorLog "/hosts/$host/_server/logs/error_log"
CustomLog "/hosts/$host/_server/logs/access_log" combined
DocumentRoot "/hosts/$host/httpdocs"
<Directory "/hosts/$host/httpdocs">
Options Indexes FollowSymLinks ExecCGI
AllowOverride AuthConfig Limit
order allow,deny
Allow from All
</Directory>
ScriptAlias /cgi-bin/ "/hosts/$host/cgi-bin/"
<Directory "/hosts/$host/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
# Server Options (PHP, mod_perl,...)
Include "/hosts/$host/_server/host_settings.conf"
</VirtualHost>
# HTTPS Server
<IfDefine SSL>
<VirtualHost *:443>
ServerName $host:443
ErrorLog "/hosts/$host/_server/logs/error_log"
CustomLog "/hosts/$host/_server/logs/access_log_ssl" combined
DocumentRoot "/hosts/$host/httpsdocs"
<Directory "/hosts/$host/httpsdocs">
Options Indexes FollowSymLinks ExecCGI
AllowOverride AuthConfig Limit
order allow,deny
Allow from All
</Directory>
ScriptAlias /cgi-bin/ "/hosts/$host/cgi-bin/"
<Directory "/hosts/$host/cgi-bin">
SSLOptions +StdEnvVars
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/hosts/$host/_server/ssl/server.crt"
SSLCertificateKeyFile "/hosts/$host/_server/ssl/server.key"
<Files ~ "\.(cgi|shtml|phtml|php|pl?)$">
SSLOptions +StdEnvVars
</Files>
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
# Server Options (PHP, mod_perl,...)
Include "/hosts/$host/_server/host_settings.conf"
</VirtualHost>
</IfDefine>
# DAV Server
<IfDefine DAV>
<VirtualHost *:81>
ServerName $host:81
ErrorLog "/hosts/$host/_server/logs/error_log"
CustomLog "/hosts/$host/_server/logs/access_log_dav" combined
DocumentRoot "/hosts/$host"
<Directory "/hosts/$host">
Options FollowSymLinks
AllowOverride none
order allow,deny
Allow from All
#DAV Settings
DAV On
#Authentication
AuthName "DAV for $host"
AuthType basic
AuthBasicProvider file
AuthUserFile "/hosts/$host/_server/users.db"
Require valid-user
#Remove filter for dynamic content
RemoveHandler .pl .cgi .shtm .shtml
RemoveType .php .phps .phtml
<Files ~ "^\.ht">
Order allow,deny
Allow from all
</Files>
</Directory>
</VirtualHost>
</IfDefine>
</Macro>
# Host Configuration
Use VirtualHost localhost
|
Note: You need mod_macro for this to work.
This is provided asis and i can't promis it will work for you.
host_manager.pl has some limitations to it that doesn't make it ideal for live server (aka not doing a gracefull restart) I won't fix this for you. Nor can I be held responsible for possible bugs in this. It works fine for me and does what I want it to do. |
|
Back to top |
|
DeliriumServers
Joined: 17 Jun 2006 Posts: 54 Location: H Town
|
Posted: Fri 13 Oct '06 18:45 Post subject: |
|
|
doesn't having a whole lot of virtual hosts also slow down apache significantly
@jorge -k restart is different than restarting with the apache monitor right?
since apache monitor restart for me causes a loss of service (apache down) for a few seconds. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Fri 13 Oct '06 19:52 Post subject: |
|
|
httpd -k restart should in theory handle all current open requests, reread the conf file, continue with new settings |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7402 Location: EU, Germany, Next to Hamburg
|
Posted: Fri 13 Oct '06 20:16 Post subject: |
|
|
-k restart is the best way to have smallest downtime with apache. Under *nix based systems -k graceful is the better way to restart.
Quote: |
doesn't having a whole lot of virtual hosts also slow down apache significantly
|
I haven't noticed loosing preformance using vhosts. Have tested it under Windows with 12 vhost and under freeDSB with 40 vhosts. I only noticed that apache used a lot more RAM under freeDSB. Can tell you that RAM usage grows under windows, because I haven't tesed it yet.
Most big hosters uses mass vhosting. if there should be seperate RAM for each host hosters uses XEN or something like that.
See http://httpd.apache.org/docs/2.2/vhosts/mass.html for good examples how developers think mass vhosts works. |
|
Back to top |
|
AMailer
Joined: 25 Sep 2006 Posts: 45 Location: Canada
|
Posted: Sat 14 Oct '06 3:56 Post subject: |
|
|
I got a question, in php, when uploading an avatar from a url - this is where it gets its 'tmp' folder path:
Code: | $tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : './' . $board_config['avatar_path'] . '/tmp';
$tmp_filename = tempnam($tmp_path, uniqid(rand()) . '-'); |
Now, with open_basedir enabled, you'll start getting a denied access... how would one by pass this? Is there a way to change, like /tmp to an alias to a path thats in the open_basedir restrictions? How is this done? |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7402 Location: EU, Germany, Next to Hamburg
|
Posted: Sat 14 Oct '06 9:59 Post subject: |
|
|
you should set into your vhost a new tmp dir for each user.
folder structur could be
C:\users\AMailer\
C:\AMailer\ tmp
C:\AMailer\htdocs
in the vhost you can set (httpd.conf)
php_value upload_tmp_dir C:/AMailer/tmp
php_admin_value open_basedir C:/users/AMailer
C:\users\James\
C:\James\ tmp
C:\James\htdocs
in the vhost you can set (httpd.conf)
php_value upload_tmp_dir C:/James/tmp
php_admin_value open_basedir C:/users/James |
|
Back to top |
|