How to Set Up Virtual Host with MAMP on a Mac OSX

1. Update the hosts file:
We are going to add an example domain named “” as a virtual host through this tutorial. Lets first add this in the “hosts” file by typing the following command on the Terminal,
[sourcecode lang=”bash”]sudo nano /etc/hosts[/sourcecode]
Then find the following line,
[sourcecode lang=”bash”] localhost[/sourcecode]
update this to following,
[sourcecode lang=”bash”] localhost[/sourcecode]
Also to add our domain to the IPv6 version find the following line somewhere bottom of the file,
[sourcecode lang=”bash”]fe80::1%lo0 localhost[/sourcecode]
update this line to the following one,
[sourcecode lang=”bash”]fe80::1%lo0 localhost[/sourcecode]
Finally press “ctrl+x” and then “y” to save and exit this file.

2. Update httpd.conf file
Open up this file by typing the following command,
[sourcecode lang=”bash”]sudo nano /Applications/MAMP/conf/apache/httpd.conf[/sourcecode]
find out the following line,
[sourcecode lang=”bash”]#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf[/sourcecode]
It might have a “#” symbol at the very beginning of the line. Delete the symbol to activate this statement. If the line is not anywhere of the “httpd.conf” file then add the above line anywhere of this file. Now, save and exit this file.

3. Update httpd-vhosts.conf file
Now go into the “/Applications/MAMP/conf/apache/” folder by executing,
[sourcecode lang=”bash”]cd /Applications/MAMP/conf/apache/[/sourcecode]
If you can see a folder named “extra” then enter inside it otherwise create this “extra” folder and then enter inside it.
Now update (If there was already a “extra” folder then there should be a “httpd-vhosts.conf” file other wise just create the “httpd-vhosts.conf” file inside “extra” folder) the “httpd-vhosts.conf” file by typing the following,
[sourcecode lang=”bash”]sudo nano httpd-vhosts.conf[/sourcecode]
Then the final “httpd-vhosts.conf” file should have the following code block. Whether you add these lines or updated the existing file.
[sourcecode lang=”bash”]
NameVirtualHost *:80

DocumentRoot "/Applications/MAMP/htdocs"

<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/thisdayinbangladesh/public"
<Directory "/Applications/MAMP/htdocs/thisdayinbangladesh/public">
Options All
AllowOverride All
Order allow,deny
Allow from all
Here “thisdayinbangladesh” is a project directory; actually a laravel4 project directory inside my “htdocs” folder and we added the “public” folder thats resides in “thisdayinbangladesh” folder as the document root cause laravel4 needs to point to the “public” folder as the application root URL.
In this stage of this example. You can forget about laravel4 and simply create the directory “/thisdayinbangladesh/public” inside your “htdocs” folder and place a simple “index.html” file there inside the “public” folder.

4. Restart:
Simply stop and re-start the Apache service from your MAMP control panel. Then try out the URL on your browser. You should see your “index.html” file!

This tutorial will take you through out a nice series of posts on which a full laravel4 web application has been developed. That service is already LIVE HERE. So, stay tuned!

The next tutorial is ready Installing Laravel4 in Mac OSX with MAMP. So, you are another step close toward the full laravel4 application development series.