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.
- 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”.
- Then, Edit your hosts file by typing the following command in your Terminal application. It should prompt you to enter the admin password.
- You should see the following contents.
And you should add your own “127.0.0.1” line with your desired name, i.e. sitename.com (Highlighted in white) and save the file.
- 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).
- 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.
- Restart MAMP by clicking “Stop Servers” then “Start Servers”.
- Finally, open your browser and go to “http://local.sitename.com” and your should see the local version of your site.