How can I set up virtualhost for multiple domain name on Windows?
I will use it for my own test projects. I have three projects that I need to set up and at the moment I'm using xampplite for the portable Apache.
I also need to access on another project, but it just like typing http://localhost/my-project/
How can I write the vhost configuration for that?
This file is located at C:\MAMP\bin\apache\conf\extra\httpd-vhosts. conf .
The first step is to create a <VirtualHost> block for each different host that you would like to serve. Inside each <VirtualHost> block, you will need at minimum a ServerName directive to designate which host is served and a DocumentRoot directive to show where in the filesystem the content for that host lives.
You need to do several steps in order to make this work.
Update the hosts file. On Windows XP, you can find it under c:\WINDOWS\system32\drivers\etc\
. You should already see the first line from below. It takes care of your mentioned other project. Add the additional ones to make any requests to the mentioned virtual hosts routed back to your own machine.
127.0.0.1 localhost 127.0.0.1 foo-bar.com 127.0.0.1 abcdef.com 127.0.0.1 qwerty.com
Update the vhosts file in Apache configuration. Under your XAMPP folder, add the following to apache\conf\extra\httpd-vhosts.conf
and if needed change the ports (i.e., if you use 8080 instead of port 80).
<VirtualHost *:80> DocumentRoot C:/xampplite/htdocs/foo-bar/ ServerName www.foo-bar.com </VirtualHost> <VirtualHost *:80> DocumentRoot C:/xampplite/htdocs/abcdef/ ServerName www.abcdef.com </VirtualHost> <VirtualHost *:80> DocumentRoot C:/xampplite/htdocs/qwerty/web/ ServerName www.qwerty.com </VirtualHost>
Do a quick configuration check. Open {XAMPP-folder}\apache\conf\httpd.conf
your file and make sure that the following part is not commented out by a preceding #
character:
Include conf/extra/httpd-vhosts.conf
Restart XAMPP.
... and you should be all setup now. Your other project should be accessible at the URI you mentioned if you just put it under C:/xampplite/htdocs/my-project/
.
To get C:/xampp/htdocs/my-project/
working, I had to add the following (default?) VirtualHost to apache\conf\extra\httpd-vhosts.conf
(in step 2 of MicE's tutorial).
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs" ServerName localhost </VirtualHost>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With