Tania Rascia

Skip Navigation
Setting Up Virtual Hosts

Setting Up Virtual Hosts

 /  127 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.

As of 2017, Chrome no longer allows .dev domain endings for local websites. Consider using .test instead.

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.


Hi, my name is Tania Rascia. I've turned down every offer for advertisements or sponsored posts on this website. I write free resources that have helped thousands of people successfully transition into a web development career.

My committment is to no bullshit, no sponsored posts, no ads, and no paywalls. If you enjoy my content, please consider supporting what I do.

Support my work


New articles on web development every two weeks.

Write a response

Your email address will not be published.

All code will be displayed literally.


  • IRMA says:

    Hi Tania, thanks for this information, but before of my virtual host configuration, the file styles.css worked well, now, after of virtual host, it doesn't.

    Could you help me please?

  • Rob says:

    Thanks for the great tutorial Tania. I am new to MAMP and your guide help me to set up the virtual hosts which I was struggling with. Nice one!

  • Mario says:

    Thank you for this great instructions, I managed to set it up, for the most part… for some reason http://example.dev is pointing to the localhost root folder, instead of the folder /Applications/MAMP/htdocs/example.dev where it is located.

  • Saksham says:

    Excellent post. Nicely explained steps that are easy to follow.
    Thanks for this.

  • Lewis says:

    Excellent post.

  • Cal says:

    I ran into problems.

    I'm running Windows 7
    I modified the httpd.conf file removing # in front of "Include conf/extra/httpd-vhosts.conf"
    I could not find the conf/extra directory or httpd-vhosts.conf file anywhere so I created them.

    I still can't get it to work.


  • Preethi says:

    Simple and easy to follow and it works the very first time. Thank you Tania!

  • Robyn Nysschens says:

    Couldn't get the command in windows command line to work. I am stuck if anyone can help.

  • Aigars says:

    I don't usually comment, but this was really useful (especially points 1 & 2 which, for some reason, really are not mentioned anywhere else).


  • Carlos says:

    Thank you Tania! X

  • Anonymous says:

    Disregard previous post. After adding the domain to ampps, it works just fine. Didnt even need to complete the additional steps of removing port calls from the url

  • Anonymous says:

    Followed the examples here. Seems pretty straight forward. Unfortunately, after completing it and testing, while the domain name I used does work in a browser, it shows me the directory listing of the files in the original server host. My guess is the host file entries are right, there is an issue with the related path in the config files (?).

  • MBlight says:

    I am following this tutorial on a PC. Once I set the document root to C:\MAMP\htdocs there is no location called extra/httpd-vhosts.conf.

    I have quit out and gone in to MAMP several times. To no avail.

    Does changing the Document Root after editing the httpd.conf file to have Virtual hosts trigger the addition of the extra folder, or should it have been there at the start of this exercise?

  • Tbo says:

    Disregard the previous post – after trying back and forth with and without the second virtual host and saving httpd-vhosts.conf several times it suddenly works.

    Thank you for the tutorial πŸ™‚

  • Tbo says:

    It works up to: “And now it works! You can repeat the code as many times as you want, for as many virtual hosts as you want.”

    When adding another virtual host in httpd-vhosts.conf I am unable to start the server again (“Apache couldn’t be started. Please check your MAMP installation and configuration.”).

    Removing the extra virtual host “solves” the problem (Apache restarts) – but I really wanted more than one host, so what can be wrong? I have tried to add another line in etc/hosts, without luck. I have tried removing :80 from the VirtualHosts tag, without luck.

  • Ben says:

    Hello Tania,

    Thank you for writing this tutorial. After getting MAMP up and running on my Windows environment (first tutorial), I can access localhost and the index.php file that we put there. Then, after following the steps in this tutorial, I can access http://example.test and the index.php file we put there. HOWEVER, now localhost no longer works. I get “Not Found, The requested URL / was not found on this server.” I have uninstalled and reinstalled and followed the directions again, same result. Any ideas about what might be going on?

    Thank you!

    • Ben says:

      On a stackexchange post for XAMP I found the following solution which worked for me. Once virtual hosts is turned on, you need to configure a virtual host to point to localhost. In C:\MAMP\bin\apache\conf\extra\httpd-vhosts.conf, I added the following and it started working:

      ServerName localhost
      DocumentRoot “C:/MAMP/htdocs”

      Options Indexes FollowSymLinks Includes execCGI
      AllowOverride All
      Order Allow,Deny
      Allow From All

      • Ben says:

        Sorry, in the above post some of the information doesn’t show up. I followed the format from Tania’s tutorial for adding a virtual host, with servername localhost, directory pointing to c:/MAMP/htdocs, etc.

  • Marc says:

    Thanks so much for your article! Really helpful and saved me a lot of time πŸ™‚

  • Miles Walker says:

    Hello Tania,

    pure respect for making this tutorial, just just finished the dev environment one and its gone so well so far. I’m a designer trying to get into dev but have no idea where to start with virtual host and environments so this has really helped me!

    I got to the end of step 4 but when I paste in the url I get this error

    This site can’t provide a secure connection
    example.test sent an invalid response.
    Try running Network Diagnostics.

    I really don’t know where i’m going wrong and hoped you’d be able to clear it up for me.

    Many thanks

    • Tania says:

      This means you’re trying to connect to an SSL (https) connection. I don’t know why it ended up like that for you, but you’ll have to figure out that on an individual basis by researching posts like this. Your localhost might already be configured to SSL, or something along those lines. You can also try using another browser. I haven’t run into this issue myself.

      • Miles Walker says:

        Hi Tania,

        after going through the tutorial again from scratch I managed to overcome the issue, I had missed off your note about .test

        the issue I face now is when I open the url the browser opens

        Index of /

        instead of the actual php file. is there a reason for this?

        thanks for your patience

  • Larson Kendrick Woodall says:

    Hey for some reason my htdocs folder is empty, what should I do?

  • Preston says:

    This is legit….hours of researching, and this is the golden post. Thank you kindly for your labor in producing this!!!

  • Stan says:

    Just want to say thank you for your detailed article. It really helped me to setup a virtual host with MAMP. So thank you!

    However, a very strange thing happened is that Google chrome suddenly cannot access my host out of the blue. The rest of the browser I’ve tried works fine. I’ve also tried pinging my project folder “ping myproject.dev” and got timeout. Is this normal?

    Request timeout for icmp_seq 0
    Request timeout for icmp_seq 1
    Request timeout for icmp_seq 2
    Request timeout for icmp_seq 3
    Request timeout for icmp_seq 4
    Request timeout for icmp_seq 5

    Look forward to your advise.

    • Oscar says:

      It started happening to me too. I had four websites running on my local machine with virtual hosts and now none of them work. All my settings were gone as well when i checked the files i edited a few months ago when I originally set this up.

    • David Sanchez says:

      Some of the issues below (like Stans and Oscar) happened to me after updating to High Sierra. You need to run Homebrew in your terminal. https://brew.sh/

      On step #3, adding the Virtual Hosts: Delete the 2 example hosts. Just have the add the 1 host you need.

      There was also a problem with MAMP not loading Apache but there’s several workarounds for this. Anyways, this tutorial is fine but If you’re upgrading to Sierra/High Sierra you might have some issues.

      I got mine to work but its very glitchy ever since I made the update on my Mac.

    • Ibas says:

      Hi Stan.

      This could happen if your localhost domain is .dev. As of Chrome 63, Chrome force .dev domains to HTTPS via preloaded HSTS.

      What this means is .dev basically won’t work at all anymore unless you have proper signed SSL certificate — no more self signed certificates allowed!
      So to fix this issue .test is one recommended domain because it is reserved by IETF for testing / dev purposes. You should also be able to use .localhost for local dev.

  • Anthony says:

    Hi Tania,

    You are my go to resource for tutorials, tips, and all things responsive and dynamic for creating a site. I have a 410 page e-book that claims to teach you what you need to know about connecting to, and creating, a MySQL database with PHP programming skills. Your Database creation tutorial covered everything in the same fashion, maybe even better, in about 400 pages less. That being said I have to jump in to help you fix this article about setting up virtual hosts. You mixed a few things up, at least I think you may have in my opinion.

    C:/ > C://MAMP > conf > apache > httpd.conf => The file you told us to alter.
    – is not the file you want to be tinkering with. it’s close, but you skipped a folder.
    The file we are uncommenting and including conf/extra/httpd-vhosts.conf doesn’t exist…
    It may actually exist for MAMP Pro, but not for regular MAMP.
    C:/ > C://MAMP > bin > apache > conf > extra > httpd.conf
    – This is the file you are after. In step 2 you write directions to alter Options
    IndexesFollowSymlinks override like this:

    Options Indexes FollowSymLinks
    AllowOverride None

    This line of code does not appear in the file you have listed in this tutorial, what
    makes it more confusing is that there are many, many, many instances where the code is
    similar, but ends up being incorrect which I assume will throw many people off.
    Step 3:
    C://MAMP/ conf/extra/httpd-vhosts.conf
    – This is the directory you posted to find the correct file and add your virtual host.
    The code to write is spot on but something is not quite right.

    – This is the true directory. If you apply the same instructions you already give us to this file instead.

    Final thoguhts:
    Your last step is no longer necessary, WordPress comes pre-installed with apache
    and Nginx both at 80.
    FOR WINDOWS USERS HAVING TROUBLE WITH STEP 4??: Let me make your life 10x easier. To run something like a notepad As the administrator (which you will need to do in order to write to the hosts file) simply open your start menu, scroll to notepad, right click it, then when the options pop up select more. Here will pop out an option called ‘run as administrator’, you’re going to select that option and navigate to System32/Drivers … At this point folders and files may be hidden so you have to type them in to filename yourself and complete the directory. After it’s finally open just follow Tania’s instructions and you are good to go!!

    After all is done all that’s left is the final step. Go to buzzfeed .com and FINALLY you can select ” See Miley Cyrus’s top 10 breakfast cereals”. Because that’s why were doing all this right? … No? well at the least you’ve now oficially set up a working virtual private server on your computer.
    *Quick updatte. I noticed you were a bit closer to the right file selection on the Mac walkthrough. Oh and one ohter thing, when you download MAMP it gives you the option for a free 14 day trial of MAMP Pro which is pre-selected for you when you in stall. If you choose to do install, which I didn’t, some of the files and directories are altered. That may palay a part too.

    Once again Tania you are my #1 source of advice particular to my chosen stack and general field. There is absolutely nobody who breaks it down better then you out there…. I am anxiously awaiting an “Advanced Content Field’ tutorial in WordPress. It’s a complete game changer and you need to get on that, I am am desperate to hear your take.

    If you need me for anything else check out my freelance website design company at https://mainfram3web.com or email me at [email protected]

    Thanks again.

    • steve says:


      I am not using MAMP PRO, and I was able to find all files and lines of code as mentioned in this tutorial.

      Although the result was not successful, as I was faced with ‘Index of / ‘ page, instead of an actual website, with regards to the files and codes, I found them all.

  • Rashid says:

    Dear Tania

    I am working on same issue and using WAMP server (WampServer Version 3.0.6 64bit), on Windows 7. I followed all the steps you mentioned above but in the I could not access my Website via virtual host URL.

    I changed my host file as below.
    # Copyright (c) 1993-2009 Microsoft Corp.
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a ‘#’ symbol.
    # For example:
    # rhino.acme.com # source server
    # x.acme.com # x client host

    # localhost name resolution is handled within DNS itself.
    # localhost
    # ::1 localhost icrrs.bop

    I have mapped port 8081 on my system my server’s IP address is

    I have followed all steps you mentioned to change httpd.conf file.

    My httpd-vhost file look like below

    # Virtual Hosts

    ServerName localhost
    DocumentRoot c:/wamp64/www

    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local


    ServerName icrrs.bop
    DocumentRoot “C:/wamp64/www/ICRR”

    Please guide… I am trying to do this from last two months.


  • 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.