Question

I've got Apache working properly, virtual hosts work as expected. My operating system is Windows 7.

However, I've got one problem, which I'm trying to find the answer to, and Google didn't yield much - for Windows anyway, only for Linux (which is not really applicable in this case).

How do I add new virtualhosts without restarting the server constantly?

(Apache version 2.2 is what I'm currently running)

I add new hosts to the host file and files in vhosts, like so:

<VirtualHost *:80>
ServerName  host1.tld
ServerAlias www.host1.tld
DocumentRoot /www/vhosts/host1.tld
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts/host1.tld">
    Options All
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

<VirtualHost *:80>
ServerName  mywebsite.com
ServerAlias www.mywebsite.com
DocumentRoot /www/vhosts/mywebsite.com
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts/mywebsite.com">
    Options All
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

Has anyone been in a similar solution, and if so, what's your advice?

Was it helpful?

Solution

You can restart apache without restarting the server. I have an apple script on my mac that restarts apache for me so that with one click and a quater of a second the new apache configuration can be loaded. Here is the apple script which can easily be ported to Python(for your Windows use):

set stopString to do shell script "sudo /usr/local/apache2/bin/apachectl stop" with administrator privileges and password
set startString to do shell script "sudo /usr/local/apache2/bin/apachectl start" with administrator privileges and password

if startString as string = "" then
    "Apache started correctly"
else
    stopString & " , " & startString
end if

OTHER TIPS

You may be able to configure all vhosts with a single block, using VirtualDocumentRoot

<VirtualHost *:80>
UseCanonicalName Off
VirtualDocumentRoot /www/vhosts/%0
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts">
    Options All
    AllowOverride All
    order allow,deny
    allow from all
</Directory>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top