Tania Rascia Web Design and Development

Skip Navigation
Setting Up Virtual Hosts

Setting Up Virtual Hosts

/ 91 responses

Did you read about how to set up a local server environment, or do you already know how to do that? The next step is setting up virtual hosts. I’ve found most – if not all – of the resources and tutorials about setting up virtual hosts to be lacking. I’m going to set it up for the first time on the laptop I’m on, so I’ll be able to guarantee every step.

At this point, MAMP is set up, and going to http://localhost:8888 will take you to the document root you set.

1. Allow virtual hosts


In Finder, go to Applications > MAMP > conf > apache > httpd.conf and open the file with your text editor.

Find this line:

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

Uncomment the code by removing the hash symbol.

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

In File Explorer, go to C:/ > MAMP > conf > apache > httpd.conf and open the file with your text editor.

Find this line:

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Uncomment the code.

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2. Allow SymLink Override

Find this line in that same httpd.conf file.

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride None

You’re going to change None to All.

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All

3. Add the virtual host path

First of all, open MAMP, and ensure the document root is Applications > MAMP > htdocs. This is the default, but if you’ve been using localhost, you may have moved it.

All the way at the end of the extra/httpd-vhosts.conf file, you’re going to place a code that signifies a virtual host and specifies the path. Place this code at the end of the document.

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

Change the DocumentRoot to wherever your PHP project is located. This is my path, but yours will of course be different.

DocumentRoot "/Users/tania/sites/learnphp"
DocumentRoot "C:/Users/tania/sites/learnphp"

Make sure to restart the servers on MAMP after making any changes! If you don’t reset the server to apply the changes, nothing will work even though you know you’ve done everything right. Trust me, I’ve done that too many times.

4. Allow your computer to recognize your local domain


Open the Terminal application. It doesn’t matter if you don’t know how to use Terminal or the command line; you only need to follow strict commands right now. (However, please read this guide when you decide to learn it!)

Type this in Terminal.

sudo pico /etc/hosts

You will be prompted for your password. Then a scary screen will come up that looks like this.

## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## localhost broadcasthost ::1 localhost fe80::1%lo0 localhost example.dev

You are actually editing a text based file. At this point, I’m just going to keep pressing the down arrow until I reach the end of the list. At the next line, I will type my new server name after, which is the computer’s local address. example.dev

Now press ctrl + o – Not cmd + o – to save the file. Press enter to confirm. And press ctrl + x to exit.


If Notepad is open, close out of it. This time right click on Notepad and select “Open as Administrator”. Open this file in Notepad:


At the bottom of the file, type the name of your virtual host. example.dev

At this point, the Window’s installation of Virtual Hosts is complete! Go to example.dev in your browser. Make an index.php file with the contents <?php echo 'Hello, world!' ?> and place it in the directory to test.

5. Remove :8888 from custom server URL

Almost done! After restarting your MAMP server, you can go to http://example.dev:8888 and it will take you to your path.

That’s pretty good. But, I want to make this perfect. I want to remove the :8888 from the end of the URL.

Back in the httpd.conf file, find these two instances (they won’t be next to each other):

Listen 8888
ServerName localhost:8888

And change them to this:

Listen 80
ServerName localhost:80

Save the file. Finally, in MAMP, Preferences > Ports, change the ports to 80, 8888, and 3306.

Restart your servers and try http://example.dev in your browser.

And now it works! You can repeat the code as many times as you want, for as many virtual hosts as you want.

<VirtualHost *:80>
  ServerName website1.dev
  DocumentRoot "path/to/website1"

<VirtualHost *:80>
  ServerName website2.dev
  DocumentRoot "path/to/website2"

If the above example doesn’t work, try removing :80 from the VirtualHosts tag, as this seemed to fix the problem for anyone having an issue. However, I just tested this April, 2017 on a new MAMP and new computer, and I can confirm if you follow it exactly you won’t have an issue.

Thank you for reading! I'm Tania Rascia, and I write no-nonsense guides for designers and developers. If my content has been valuable to you, please help me keep the site ad-free and continuously updated with quality tutorials and material by making a donation. Any amount helps and is greatly appreciated! Otherwise, let me know any ideas you have on a course you'd be eager to see.

Write a response

Your email address will not be published.


  • Todd says:

    Tania, I can’t thank you enough for your clear, well-written tutorials.

  • Monok says:

    Hello Tania, and thanks for this helpful guide! Only one question: I’ve set up a virtual host as you said on Windows 10, using MAMP – not the Pro version, tho! – and then tried to browse ‘example.dev’, but it gives me the 403 Forbidden error. I’ve tried googling for a solution or a workaround, even checked StackOverflow, but it seems that no one has this problem but me. Whoever has this problem owns the Pro version, and it’s solved by checking something on a setting, but I don’t have those settings on my not-Pro-version of MAMP. Any idea on what can I do to solve it?

    Thanks in advance, and thanks again for this helpful blog!

  • Beth says:

    Thank you so much for writing this, I’ve got mine up and running!
    The first time round it didn’t work, and I think it might be in the wording of the last part (about removing :8888 from the custom server URL.)
    For anyone who found it stopped working at this stage, make sure you’re simply changing Listen 8888 to Listen 80, and then changing ServerName localhost:8888 to ServerName localhost:80.
    Tania maybe change the wording around “change it to this” or separate the lines of code out so people aren’t copying and pasting the two lines!

    Thanks again for the article, moving on to your wordpress one now!

  • Sara says:

    This was very clear and helpful! Thanks for writing this up in such an easy-to-follow format. You’re absolutely right that the resources online for doing this sort of thing are not always the greatest.

    My only suggestion is to mention the warning about removing the :80 from the virtual host tag sooner (probably right before the section about removing the :8888). I was stuck in that spot for a while because I didn’t want to move on until I got it working.

  • Daniel says:

    I could make it work removing the :80 on the virtualhosts file.. But i can”t remove :8080 from the url.. Apache says there is already a process on that port (80).. I think is IIS.. since i work with asp.net.. how could i make it work on 8080?

    • Kevin Conklin says:

      You could look into your computer “services” (if you have PC just search for Services and click enter) find and stop “World Wide Publishing Services” it runs on port 80 by default [if skype isnt already hogging it]. Once you turn that off, it should accept port 80.

Tania's List

My tutorials, guides, and articles for web designers, developers, and autodidacts, sent out once a month or so. No bullshit, ads, or tricks.