I can't get virtual host to direct the second site correctly

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

I can't get virtual host to direct the second site correctly

Postby dmphotography » 16. December 2008 10:02

Hey everyone,
I know there's topic after topic about this and I hate starting a new thread, but I've tried everything I've read and so far nothing has worked. Plus, I'm not totally clear on a few things about the second website.
I used Xampp to install all the goodies. I then installed a phpBB forum. Everything works great. http://www.domain1.com goes to where it needs to. Now I want to add a second forum or html website. The first one is in B:/xampp/htdocs. I wanted to put the second one in B:/xampp/htdocs2. My httpd-vhosts.conf reads like this:

NameVirtualHost *:80

<VirtualHost www.domain2.com:80>
ServerName www.domain2.com
DocumentRoot "B:/htdocs2"
</VirtualHost>

<VirtualHost www.domain1.com:80>
ServerName www.domain1.com
DocumentRoot "B:/xampp/htdocs"
</VirtualHost>

My server is behind a router and my servers local IP is 192.168.1.107 and port 80 is forwarded. All traffic goes to B:/xampp/htdocs no matter how I try to configure it.

What am I doing wrong and how do I fix it?

Also, where does my directory for site 2 have to be to use the PHP and MySQL from site 1?

Thank you very much for your help.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
Operating System: Windows 7

Re: I can't get virtual host to direct the second site correctly

Postby Sharley » 16. December 2008 10:46

Try this and see how it pans out:
Code: Select all
NameVirtualHost *:80

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

<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot "B:/xampp/htdocs/forum"
</VirtualHost>

<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot "B:/xampp/htdocs2/forum2"
<Directory "B:/xampp/htdocs2/forum2" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<Virtualhost> should be the same as NameVirtualHost line ie:*.80
which is a wild card name virtual host and should suit your needs.

Make sure B:\xampp\htdocs2\forum2\ folder exists - because it is outside the server's default DocumentRoot directory htdocs then it must have directory permissions set as above.

The domain in the B:\xampp\htdocs\forum\ folder is covered by the defaults in the httpd.conf file for permissions etc.

Both domains above will use the resources of your XAMPP installation ie:Apache, PHP and MySQL.

Let me know if we need to tweak this further as the above is only an example and don't forget to restart your server after editing any conf and or ini files.

You should be able to visit using the following:
http://localhost
http://domain1.com
http://www.domain1.com
http://domain2.com
http://www.domain2.com

You may also have to edit your Windows HOSTS file.

BTW having 2 instances of XAMPP running at once will not work, use the above on only one of your instances of XAMPP and get rid of the other (delete the other), you don't need it when you use VirtualHost.
( I read your other thread which seemed to indicate you installed XAMPP twice).

Here's a variation using just one htdocs folder and should produce the same results:
Code: Select all
NameVirtualHost *:80

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

<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot "B:/xampp/htdocs/forum1"
</VirtualHost>

<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot "B:/xampp/htdocs/forum2"
</VirtualHost>
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

Re: I can't get virtual host to direct the second site correctly

Postby dmphotography » 16. December 2008 11:36

THANK YOU VERY MUCH!!!! Haha. Hours and hours of messing with it and it works perfect now. I'm a very visual learner (which means coding can be rather difficult to learn) and it seems like everyone wants to describe it in the most difficult and technical way possible. I on the other hand have to picture how it works, then be able to sort it out. This whole project began as a learning experience, from setting up my own dedicated server, routing my domain names through a DNS to my IP, port forwarding through my routers firewall, then successfully setting up a php forum. I tried installing PHP and my SQL the hard way . . . that was a miserable waste of time. So once I got this one up and running, I wanted to learn more and figure out how to seperate two domain names on a single IP address.

Now what I'm still not seeing is this: I've got two domains, we'll use google.com and yahoo.com as an example. They both go to my single ip through port 80, which forwards to my computer located at local IP 192.168.1.107. Now once yahoo.com and google.com reaches my server, how does the virtual host tags tell them apart since they came in on the same IP, same port?

Secondly, if a third domain was added, it'd be as simple as adding another Virtual Host tag defining domain3 and it's Document Root?

And lastly, What is this tag telling it to do?

Code: Select all
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny


Thank you again very much for your help and amazingly fast response!

P.S. I tried installing it twice because I didn't understand if you had to have a whole new instance of apache, MySQL, PHP, etc. for a second site or if it was all ran from the same core components. People need to draw more pictures and type less. LOL.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
Operating System: Windows 7

Re: I can't get virtual host to direct the second site correctly

Postby Sharley » 16. December 2008 12:04

dmphotography wrote:Now what I'm still not seeing is this: I've got two domains, we'll use google.com and yahoo.com as an example. They both go to my single ip through port 80, which forwards to my computer located at local IP 192.168.1.107. Now once yahoo.com and google.com reaches my server, how does the virtual host tags tell them apart since they came in on the same IP, same port?
We use an IP wildcard so the Apache server listens for a connection from any IP on port 80.
It destiguishes each by its ServerName and ServerAlias (name) and servers up the contents in the respective DocumentRoot directories.


dmphotography wrote:Secondly, if a third domain was added, it'd be as simple as adding another Virtual Host tag defining domain3 and it's Document Root?
Correct. It's just multiples after getting the first one right - you can have as many as your server resources can handle.
You can have the DocumentRoot and it's <Directory> directive anywhere on your computer using the VirtualHost container in your httpd-vhost.conf file.
http://httpd.apache.org/docs/2.2/vhosts/
http://httpd.apache.org/docs/2.2/vhosts/examples.html


dmphotography wrote:And lastly, What is this tag telling it to do?

Code: Select all
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
It would be better explained by going to the authoritative manual:
I know it will be hard to follow for you but read it and you will have a better understanding of all the directives that can be used in your Virtual Host environment - use it as a reference and look up each of the above directives.
http://httpd.apache.org/docs/2.2/mod/quickreference.html


Good luck, happy tweaking and sorry no pictures or cartoons. :D
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

Re: I can't get virtual host to direct the second site correctly

Postby damien4482 » 18. February 2009 10:42

ok i got the same problem however mine seems not to work altering the txt as above
i am using html for all websites. and all websites point to the first site for some reason and not picking up on the different site.i have crested the folders in the right place as stated in the vhost file. i use dynamic ip here is my httpd-vhost.conf file

NameVirtualHost *:80

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

<VirtualHost *:80>
ServerName consolegamesdirect.co.uk
ServerAlias www.consolegamesdirect.co.uk
DocumentRoot "c:/xampp/htdocs/consolegamesdirect.co.uk"
</VirtualHost>

<VirtualHost *:80>
ServerName consolegamesdirect.mine.nu
ServerAlias http://consolegamesdirect.mine.nu/
DocumentRoot "c:/xampp/htdocs2/consolegamesdirect.co.uk"
<Directory "c:/xampp/htdocs2/consolegamesdirect.co.uk" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


i have also lookind into windows/system32/drivers/etc/hosts and modifyed it so it looks like this

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
127.0.0.1 www.consolegamesdirect.co.uk
127.0.0.1 http://consolegamesdirect.mine.nu

192.168.0.4 www.consolegamesdirect.co.uk
192.168.0.4 http://consolegamesdirect.mine.nu

so where am i going wrong have looked at all the many posts but with not much joy in correcting what i have
damien4482
 
Posts: 7
Joined: 19. January 2008 23:37

Re: I can't get virtual host to direct the second site correctly

Postby Izzy » 18. February 2009 10:59

Try this and post any error messages you may get - the server sorts out the http and the alias not the hosts file.

127.0.0.1 consolegamesdirect.co.uk
127.0.0.1 consolegamesdirect.mine.nu

192.168.0.4 consolegamesdirect.co.uk
192.168.0.4 consolegamesdirect.mine.nu


Remove this line as it is not an alias and so is not needed and is wrong syntax anyway:
ServerAlias http://consolegamesdirect.mine.nu/
or use:
ServerAlias www.consolegamesdirect.mine.nu
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: I can't get virtual host to direct the second site correctly

Postby damien4482 » 18. February 2009 19:25

after much trying and reading and finaly giving in and posting for help i made a sily little mistake and now thanks to you it now works perfectly many thanks
damien4482
 
Posts: 7
Joined: 19. January 2008 23:37

Re: I can't get virtual host to direct the second site correctly

Postby Izzy » 18. February 2009 19:40

Your most welcome and I am pleased it all works now as intended.
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 59 guests