How to use Apache Virtual Hosts over a local network with MAMP
I was asked recently whether it was possible to use the Virtual hosting in Apache I describe for Magento on MAMP over a network rather than just locally. To make a sensible response I wanted to give a quick background to the HTTP requests going on and how Apache uses those requests to decide what HTTP response to send back. It turned into a bit of a long reply comment so here it is as a post instead.
I use a network Apache virtual hosts setup all the time (though the network isn’t a local network it’s the internet, but same principle).
Here’s a quick little summary to clarify. Basically when your browser requests www.example.com you OS goes to try and find an IP for that address. It’ll check in your hosts file and get the IP address, then it’ll connect and the HTTP request will be sent to the server. If it can’t find the server in your hosts file, it’ll ask the DNS server, the rest is history of course. I digress, this post is more about the hosts file configuration/scenario than the DNS one. If you wanted you could set up a local DNS relay server, and remove the need for the modified hosts file at all – a story for another day!
The important part is that the HTTP request contains the original hostname (www.example.com). If you have an Apache running without virtual hosting it will just send back and HTTP response without regard for the hostname, and in fact if you have a default virtual host, it will respond when no hostname matches anyway.
When you configure Apache virtual hosts you are basically telling Apache to send back different responses based on the requested hostname in the HTTP request from the client.
SO, why did I bore you with this? Hopefully to make it easy to understand for the network setup. Provided your friend can connect to your HTTP server running on MAMP (via your IP address) and is not blocked by any firewalls it will work perfectly. The HTTP request must contain a hostname that matches your Apache running on MAMP, and you’ll be in business.
So say your macbook IP address is 192.168.1.100 and your development Magento store is called ‘www.devstore.com’. In your hosts file (/etc/hosts) you would have something like:
localhost www.devstore.com
In your friends hosts file they will need:
192.168.1.100 www.devstore.com
This tells your machine to connect to localhost when making requests to www.devstore.com and tells your friends machine to connect to 192.168.1.100. Both will cause the HTTP request sent to Apache to be for ‘www.devstore.com’ which would need to be a configured virtual host (or the only/default host) in your Apache.
I hope this clarifies it all a little, it seemed there was some confusion about the role the hosts file played in this MAMP virtual host setup. The hosts file should not contain any URL’s, it only maps hostnames to IP addresses.
You might also be interested in:
- How to set up Apache Virtual hosting on MAMP for Magento
- How to install MAMP on your Leopard Mac
- Fixing Magento Login Problem after a Fresh Installation
- How to use the MAMP Mysql command line client in a terminal
- A simple way to password protect your Magento store
Tagged as hosts file, Macbook, Magento, MAMP, Virtual Hosts + Categorized as Apache, MAMP, Mac, Magento
![Email Me: ashley.schroder[at]gmail Email Me: ashley.schroder[at]gmail](/wp-content/themes/aschroder/images/email.png)














Interesting post!
What would I do to connect to a folder on the remote machine, where my virtual host is set up? Can I do that?
Thanks
Hi, You can.
I think this post on using Magento, MAMP and virtual hosts over a network is what you need? Is that what you were trying to do?