Virtual Hosts

Virtual Hosts

If you are using XAMPP you will probably want to setup VHosts.

 

I'll focus on Windows here but the process is much the same for Linus and OSx.

Setting up a kiosk recently on a LAN I needed to have one Apache host server and multiple clients pointing at this. I needed to access the kiosk on any PC in the LAN by typing http://kiosk.local into the browser (not the IP).

1. set up a virtual host

You first need to set up a virtual host in your apache httpd-vhosts.conf file.
On XAMP, you can find this file here: C:\xampp\apache\conf\extra\httpd-vhosts.conf.
On MAMP, you can find this file here: Applications/MAMP/conf/apache/extra/httpd-vhosts.conf.

You need to provide the name of the Virtual Host as well as the root/main folder of your website. To do this, add the following line at the end of that file. You need to change the DocumentRoot to wherever your main folder is, eg 'C:/XAMPP/htdocs/MySite'

<VirtualHost *:80>

DocumentRoot "/Applications/MAMP/htdocs/MySite/"

ServerName mysite.local

</VirtualHost>

2. configure the hosts file

For the client to understand what kiosk.local means, you need to edit the hosts file on your computer.

Everytime you type an URL in your browser, your computer tries to understand what it means. So it will try to resolve the name kiosk.local to an IP address. It will do this by first looking into the hosts file on your computer to see if he can match an IP address to what you typed in the address bar. If it can't, then it will ask DNS servers. The trick here is to append the following to your hosts file.

On MAC, this file is in /private/etc/hosts;
on LINUX, this file is in  /etc/hosts;  
on WINDOWS, this file is in \Windows\system32\private\etc\hosts (if you're using WINDOWS 7, this file is in \Windows\system32\drivers\etc\hosts)

##
# Host Database
# localhost is used to configure the loopback interface
##
#...
127.0.0.1 symfony.local

From now on, everytime you type kiosk.local on this computer, your computer will use the loopback interface to connect to symfony.local. It will understand that you want to work on localhost (127.0.0.1).

3. Access symfony.local from an other computer:

Get the IP address of the computer hosting the website:

We first need to know the IP address on the computer that hosts the website. In the terminal, on MAC and LINUX type ifconfig |grep inet, on WINDOWS type ipconfig. Let's assume the IP address of this computer is 192.168.1.5.

Use the IP address of the computer we are trying to access/talk to:

##
# Host Database
# localhost is used to configure the loopback interface
##
#...
192.168.1.5 symfony.local


 

Thanks to @Mick on stackoverflow for this

Rate this blog entry:
Piwik Email Confusion
Sierra REST API

Comments

 
Guest - Susan Hermiston on October 7, 2015 16:46

Wow 747 just blew me away. Sorry not a tech person at all!! But I still love you!! Rock on!!?

Wow 747 just blew me away. Sorry not a tech person at all!! But I still love you!! Rock on!!?

Latest Comments

Susan Hermiston Virtual Hosts
October 7, 2015
Wow 747 just blew me away. Sorry not a tech person at all!! But I still love you!! Rock on!!?
Johmny Invisible Mouse Cursor Ubuntu & Synergy
September 2, 2015
Glad I was ble to help!
Kristian Falk Invisible Mouse Cursor Ubuntu & Synergy
September 1, 2015
Thank you for this! Had the exact same problem. I almost went crazy.