Setting Up Virtual Hosts on a Mac

I ran into some trouble running through different tutorials to setup virtual hosts while setting up a local Laravel site. There doesn’t seem to be much consensus on the developers’ preferred local environment. So here’s how to setup virtual hosts on a mac with MAMP. From what I understand this let’s you use a “virtual” domain name for your local host. This is based on Tania Rascia’s post(, definitely read her post for a more detailed guide.

Allow Virtual Hosts

In finder, go to Applications > MAMP > conf > apache > httpd.conf and open the file with a text editor.
Find this line:

#Virtual hosts
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Uncomment the second line.

Allow SymLink Override

In the same file find:

<Drectory />
Options Indexes FollowSymLinks
AllowOverride None

Change None to All

Add the Virtual Host Path

Ensure the document root is Applications > MAMP > htdocs. This should be default unless you have moved it.

In the extra/httpdvhosts.conf file, place a code that signifies a virtual host with path at the end of the document.

<VirtualHost *:80> 
ServerName example.test 
DocumentRoot "/path/to/directory" 

Allow Your Computer to Recognize Your Local Domain

In the terminal write:

pico /etc/hosts

Enter password.

Pico is a terminal text editor. We’ll add the new server name “example.test” after the last

Press “ctrl + o” then “enter” to save the file and “ctrl + x” to exit.

Remove :8888 from custom server URL

In the httpd.conf file, find these lines:

Listen 8888 
ServerName localhost:8888

Replace 8888 with 80 and save the file.

In MAMP Preferences > Ports, change the Apache Port to 80, Nginx Port to 8888, and MySQL Port to 3306. Your settings might already have this.

Once you restart the server the vhost should be working.

Leave a Comment