22

How do you configure MAMP to manage/host multiple websites at one time for development?

philfreo
  • 987
  • 2
  • 9
  • 22
  • you have to turn off the web sharing in system preferences –  Mar 29 '11 at 04:48
  • I don't have the reputation to comment, but I just want to point out that according to this you want to avoid editing the conf files with TextEdit: [Virtual hosts with MAMP](http://sillybean.net/web-design/virtual-hosts-with-mamp/) – Yarin Nov 23 '10 at 18:11
  • I've had no problems editing it with TextEdit – philfreo Nov 23 '10 at 20:28
  • Re: textedit- Depends on what’s in the user directory. Some things don’t do well with rtf; just set textedit to ‘plain text’. –  Mar 05 '11 at 22:52
  • Can someone please help me out here ? I am trying to achieve the same thing in MAMP http://stackoverflow.com/q/40405663/4480164 – code-8 Nov 03 '16 at 15:53

1 Answers1

41

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/

evilReiko
  • 193
  • 1
  • 7
philfreo
  • 987
  • 2
  • 9
  • 22
  • 6
    I registered in serverfault just to upvote your answer! :D – evilReiko Jun 22 '11 at 11:23
  • Me too. This is amazing, because you don't have to buy MAMP Pro (which is kind of expensive) for managing multiple sites locally just by editing two config files. – mav May 24 '12 at 09:34
  • For access forbidden error, go here: http://stackoverflow.com/questions/9110179/adding-virtualhost-fails-access-forbidden-error-403-xampp-windows-7 – zengr Dec 10 '12 at 19:34
  • 6
    There is a specific file for virtual host configs located here: `/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf` – Bryan Downing Mar 07 '13 at 01:11
  • 7
    @BryanDowning It's worth mentioning that in order for apache to use this file you have to uncomment the following line from within httpd.conf file: `Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf` – JosephWoodward Mar 13 '13 at 23:06
  • Can someone please help me out here ? I am trying to achieve the same thing in MAMP http://stackoverflow.com/q/40405663/4480164 – code-8 Nov 03 '16 at 15:53
  • After update my Apache Port from `8888` to be `80`, I can't start my Apache Server on my **MAMP**. Does anyone else experience this ? – code-8 Nov 03 '16 at 15:57