Sangat Pedas

Setting Up Multiple Host In Apache On Mac OSX

multiple-hostsSo, you are the fortunate owner of a Macbook Pro and are working on several projects. How to setup Apache to work with multiple hosts/websites on just your local IP?

The first thing you want to do is spoof your IP to some domains you want to use so those domains are routed to your local IP. To do this you need to edit your hosts file:

Next, add the domains to be resolved to your local IP:

Save and close, you can instantly test it by opening http://microsoft.local in your browser, you should get the start page of your Apache server.
Next, you need to enable the use of virtual hosts in Apache.

Next look for this line:

Change it to:

Save and exit. Now you have enable the use of virtual hosts in Apache and the only thing left is defining the virtual hosts. For this you need to edit the file httpd-vhosts.conf:

Here’s an example of how you can configure the 3 local domains we’ve defined earlier:

Now make sure the folders for your websites exist and have something in it, restart Apache and check the domains in your browser.

The only comment here is that if you already had a website running in your root (/Library/WebServer/Documents/) then that one won’t work anymore. No worries, best to create a new sub-folder, move the website there and create another virtual host for it.

Comments are closed.