Creating Virtual Hosts

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

Creating Virtual Hosts

Postby juusui » 18. May 2009 07:38

Hello,

I just started using XAMPP to work locally on the various sites that I am building/maintaining. Previously, I used Apache without XAMPP and whenever I wanted to set up a new virtual host I just modified the httpd file.

To set up virtual hosts with XAMPP, I have added the following to the httpd-vhosts.conf

Code: Select all
<VirtualHost us.local:80>
    ServerAdmin webmaster@us.localhost
    DocumentRoot F:\Our-Website\html
    ServerName us.local
    ErrorLog logs/us.local-error.log
    CustomLog "logs/us.local-access.log" common
    <Directory "F:\Our-Website\html">
            Order Deny,Allow
            Allow from all
     </Directory>
</VirtualHost>

<VirtualHost loopfuse.local:80>
    ServerAdmin webmaster@loopfuse.localhost
    DocumentRoot M:\Backup-lenovo-090513\LoopFuse\web\repository\www\v4
    ServerName loopfuse.local
    ErrorLog logs/loopfuse.local-error.log
    CustomLog "logs/loopfuse.local-access.log" common
    <Directory "M:\Backup-lenovo-090513\LoopFuse\web\repository\www\v4">
            Order Deny,Allow
            Allow from all
     </Directory>
</VirtualHost>


I also added the following to my hosts file:
Code: Select all
127.0.0.1   us.local
127.0.0.1   loopfuse.local


The problem I am having is that I get the same site for both addresses.

When I enter into the browser: us.local
I get the correct site.

When I enter into the browser: loopfuse.local
I get the us.local site.

I have tried a variety of different things, such as:
--Using a different host name (ie: us.site)
--<VirtualHost 127.0.0.1> This is what I use on my other computer - just running Apache without XAMPP

Any advice or tips would be greatly appreciated.

Thanks
Shannon Dunn
juusui
 
Posts: 1
Joined: 18. May 2009 06:59

Re: Creating Virtual Hosts

Postby Wiedmann » 18. May 2009 07:50

--<VirtualHost 127.0.0.1> This is what I use on my other computer - just running Apache without XAMPP

That's correct. And also you need a matching NameVirtualHost directive. (see your error.log)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Creating Virtual Hosts

Postby Sharley » 18. May 2009 09:59

Hello Shannon, thanks for providing much detail for us to work with.

Try this below, which I believe should work using your post as my source and if you do an advanced search in the XAMPP for Windows forum using virtualhost or vhost as the keywords they should return many other examples to compare this example with below.


Change the first localhost container from the default to your own path if different.

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
ServerName us.local
DocumentRoot "F:/Our-Website/html"
ServerAdmin webmaster@us.localhost
<Directory "F:/Our-Website/html">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
ErrorLog logs/us.local-error.log
CustomLog logs/us.local-access.log common
</VirtualHost>

<VirtualHost *:80>
ServerName loopfuse.local
DocumentRoot "M:/Backup-lenovo-090513/LoopFuse/web/repository/www/v4"
ServerAdmin webmaster@loopfuse.localhost
<Directory "M:/Backup-lenovo-090513/LoopFuse/web/repository/www/v4">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
ErrorLog logs/loopfuse.local-error.log
CustomLog logs/loopfuse.local-access.log common
</VirtualHost>
Your Hosts file is correct as long as 127.0.0.1 localhost is above and the first available entry.
Code: Select all
127.0.0.1   localhost
127.0.0.1   us.local
127.0.0.1   loopfuse.local
The above vhosts configuration should let you access:
http://localhost
the XAMPP Welcome Page in the default DocumentRoot folder

http://us.local
the site in the F:\Our-Website\html folder

http://loopfuse.local
the site in the M:\Backup-lenovo-090513\LoopFuse\web\repository\www\v4

TIP
Make sure you clear your browser's cache (delete Temporary Internet files in IE) from time to time when developing at localhost level or you could be served a cached page instead of a fresh page from the server.

APACHE DIRECTIVES
Read about all the directives in the virtual hosts configuration file:
http://httpd.apache.org/docs/2.2/mod/directives.html
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to XAMPP for Windows

Who is online

Users browsing this forum: steffenmaier and 135 guests