Page 1 of 1

Using Virtual Hosts to connect from another computer

PostPosted: 01. June 2012 10:31
by JosephDuffy
Hi,
I'm trying to get my development environment a little easier to use. I currently connect to my home server that is running XAMPP via its name, "server". This takes me to the default XAMPP page.
I also have a website set up on this, lets call it "website2". To access this website, I can remotely use "server/website2", or on the server using "localhost/website2".
I have successfully setup Virtual Hosts so that on the server I can access the website via "website2.localhost". Here is my vhosts file.

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>

   DocumentRoot "c:/xampp/htdocs"

   ServerName localhost

</VirtualHost>

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

   ServerName website2.localhost

</VirtualHost>

I also have my hosts file setup with "127.0.0.1 website2. localhost".
However, I would like to be able to access the website via "website2.server", but that is not working. I have tried editing the hosts file on my computer with "192.*.*.* website2.server" (obviously replacing the * with the actual IP), but that has not helped. Ideally, I would be able to access the website via something like "website2.192.*.*.*" across the network, so I can test my websites on other devices where editing a hosts file would be impossible (an iPhone, for example).
I'm not sure if this is possible, but I thought I would ask (:

Re: Using Virtual Hosts to connect from another computer

PostPosted: 01. June 2012 12:25
by Altrea
Hi JosephDuffy,

If you want to use a (simulated) DomainName from one computer to another, you shouldn't use the word "localhost" in it. localhost is a special identifier for the very local computer you are acting from at the moment.

To make the Domain working, there are two things that have to be true:
1st) the server where XAMPP is working on must have a valid VHost entry for that domain
2nd) the client from where the Browser sends the request must have an entry in it's local Windows HOSTS file containing the domain name and the IP of your server.

best wishes,
Altrea

Re: Using Virtual Hosts to connect from another computer

PostPosted: 01. June 2012 20:53
by JosephDuffy
Altrea wrote:Hi JosephDuffy,

If you want to use a (simulated) DomainName from one computer to another, you shouldn't use the word "localhost" in it. localhost is a special identifier for the very local computer you are acting from at the moment.

To make the Domain working, there are two things that have to be true:
1st) the server where XAMPP is working on must have a valid VHost entry for that domain
2nd) the client from where the Browser sends the request must have an entry in it's local Windows HOSTS file containing the domain name and the IP of your server.

best wishes,
Altrea

Thank you!
I have a changed the vhost and hosts file on the server to website2.server, and I also changed the hosts file on the computer I will access it from.
This works correctly on computers that I can edit the hosts file on, but do you any idea of how to get it to work on other computers (e.g. iPhones)?

Re: Using Virtual Hosts to connect from another computer

PostPosted: 01. June 2012 21:42
by Altrea
JosephDuffy wrote:do you any idea of how to get it to work on other computers (e.g. iPhones)?

Are the computers / IPhones part of a local network (LAN or VPN) or are they part of a public network (internet)?