dynamically configured virtual hosts

Problems with the Windows version of XAMPP, questions, comments, and anything related.

dynamically configured virtual hosts

Postby sheershoff » 10. January 2009 15:39

I set up dynamically configured virtual hosts using xampp - this is useful for fast creating new projects. I thought it may be useful so I post it here. Also it would be wonderful if developers comments appear.

STEP 1:

in C:\xampp\apache\conf\httpd.conf uncomment the following line:
Code: Select all
LoadModule vhost_alias_module modules/mod_vhost_alias.so


STEP 2:

replace the content of C:\xampp\apache\conf\extra\httpd-vhosts.conf with the following

Code: Select all
# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot "C:\\xampp\\htdocs\\WORK\\%0\\docs"
VirtualScriptAlias "C:\\xampp\\htdocs\\WORK\\%0\\cgi-bin"


STEP 3:

Create C:\xampp\htdocs\WORK

STEP 4:

Restart Apache

Now setting a new vhost for a new project is a bit easier - no need to edit vhosts config and no need to restart apache:

1. Put a new domain record line in C:\WINDOWS\system32\drivers\etc\hosts , e.g.
Code: Select all
127.0.0.1 example.loc

2. Create a folder with the name of the new created domain in C:\xampp\htdocs\WORK, e.g. C:\xampp\htdocs\WORK\example.loc
3. Create "docs" folder in the new folder, e.g. C:\xampp\htdocs\WORK\example.loc\docs . It's the document root folder for example.loc vhost.

These 3 things could be done by running the following batch file with the domain name as a parameter. I put it in c:\xampp\addvhost.bat, e.g.

Code: Select all
addvhost.bat newexample.loc


addvhost.bat:

Code: Select all
echo creating folders for %1
mkdir c:\xampp\htdocs\WORK\%1
mkdir c:\xampp\htdocs\WORK\%1\cgi-bin
mkdir c:\xampp\htdocs\WORK\%1\docs
echo adding %1 to windows hosts file
echo  # >> C:\WINDOWS\system32\drivers\etc\hosts
echo 127.0.0.1 %1 >> C:\WINDOWS\system32\drivers\etc\hosts
echo %1 vhost added. test it.


Hope it was useful.
sheershoff
 
Posts: 1
Joined: 10. January 2009 15:09
Location: Yekaterinburg, Russia

Re: dynamically configured virtual hosts

Postby canada97 » 14. January 2009 16:11

While this was most usefull, and showed me where I was making silly blunders that has drove me nuts I do have one thing I cannot accomplish as of yet.
I want to be able to set up for:
w1.example.com
w2.example.com
ect...
2 questions...

1: how do I modify what you have here since this is what I have with the exception of different domain names
2: Do I have to register every sub-domain with a dynus service? if so that can get expensive since there are currently 75 sub domains because I have broken up my server by topics of interest and I have a lot of intrest!

Would appreciate any help I can get!
Thanks guys, I am a newbie with Apache virtual host. My domain name is registered with dyndns if that helps!
I am not a newbie programmer, nor am I new to virtual hosting, I just have used IIs and wanted to get away from it.
I am running windows XP Pro.


The Lost and Confused...
canada97
 
Posts: 1
Joined: 14. January 2009 16:02

Re: dynamically configured virtual hosts

Postby Izzy » 15. January 2009 02:09

canada97 wrote:While this was most usefull, and showed me where I was making silly blunders that has drove me nuts I do have one thing I cannot accomplish as of yet.
I want to be able to set up for:
w1.example.com
w2.example.com
ect...
2 questions...

1: how do I modify what you have here since this is what I have with the exception of different domain names
2: Do I have to register every sub-domain with a dynus service? if so that can get expensive since there are currently 75 sub domains because I have broken up my server by topics of interest and I have a lot of intrest!

Would appreciate any help I can get!
Thanks guys, I am a newbie with Apache virtual host. My domain name is registered with dyndns if that helps!
I am not a newbie programmer, nor am I new to virtual hosting, I just have used IIs and wanted to get away from it.
I am running windows XP Pro.


The Lost and Confused...

Perhaps the above is not for you and using the httpd-vhosts.conf file in the conventional way might be much easier to set up (lots of sub-domains) apart from the fact that the wait for the OP to return and answer your questions may well be a long one.


If you paste here your conventional httpd-vhosts.conf file that you tried without success and provide the domains you wish to use and say a couple of your subdomain names and the path information, then I am confident you can be helped here to achieve your desired outcome.

This subject or keywords of vhosts or virtualhosts has been addressed on this forums almost on a weekly basis for years so there is lots of material using the forum search to get some grounding and perhaps to help relieve that lost and confused feeling.

You don't have any Vista quirks to contend with so the process is made much easier on XP boxes.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 56 guests