How to set up multiple websites / virtual hosts on MAMP? [closed]
Change your default listening port
Go to MAMP > Preferences > Ports
and set Apache Port
to be 80
. Press okay.
Set up your local hosts file
Edit your hosts file so that you have some domains that will resolve to your local web server.
From Terminal, type sudo pico /etc/hosts
and type your password. At the bottom, append the following two lines.
127.0.0.1 local.example.com
127.0.0.1 local.example.net
Save the file and exit (Ctrl+O, enter, Ctrl+X).
Add Virtual Hosts to your Apache configuration
Open up /Applications/MAMP/conf/apache/httpd.conf
in a text editor, scroll down, and add the following lines to the file.
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/YOURNAME/sites/example-a"
ServerName local.example.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/YOURNAME/sites/example-b"
ServerName local.example.net
</VirtualHost>
Restart Apache
Stop Servers and then Start Servers on MAMP. Now you should be able to visit: http://local.example.com/ and http://local.example.net/