Local Dev on Mac with MAMP

If you are doing lots of local PHP development and you hate moving stuff back and forth from your htdocs/ folder (where your default web root is located), then you should set your Mac to use virtual hosts. For example, let’s say you have a site called “sitename.com”. You could set it up so “local.sitename.com” would bring up your local development site through your web browser.

Below are the necessary steps to accomplish this feat. Note: you should have admin access to edit your hosts file.

  1. First, make sure that your MAMP environment is using port 80 by click “Preferences…” in your MAMP panel and clicking the “Ports” tab. Click “OK”.
  2. Then, Edit your hosts file by typing the following command in your Terminal application. It should prompt you to enter the admin password.
    Sudo Hosts
  3. You should see the following contents.

    Hosts File
    And you should add your own “” line with your desired name, i.e. sitename.com (Highlighted in white) and save the file.

  4. Next, navigate to “Applications > MAMP > apache” and open the “httpd.conf” file in a text editor app like TextEdit. And find the text in the file denoted by “# Virtual Hosts” (Noted as line 524 in the image). Uncomment the next line by removing the hash (#) character (Denoted in yellow in the image).
    Httpd File
  5. Afterwards, open up another file located in “Applications > MAMP > apache > extra” and open “httpd-vhosts.conf”. Add lines similiar to lines 45-48 in the image below.
    Then you should modify the contents in yellow to your desired values.
  6. Restart MAMP by clicking “Stop Servers” then “Start Servers”.
  7. Finally, open your browser and go to “http://local.sitename.com” and your should see the local version of your site.