MAMP (LAMP) for Mac – Hosting Multiple Sites (without the pro version)

Last modified on:

You don’t need to shell out for the pro version of MAMP to host multiple sites on your Mac. All it takes is a couple of tweaks behind the scenes. Once you have MAMP installed and working, configure MAMP to respond to web requests on port 80 (if you haven’t already done this). Next, simply edit your Mac’s hosts file to redirect your site URL’s to point to MAMP on your machine (127.0.0.1).

add the following lines to the bottom of your host file (/etc/hosts) using your site URL’s:

to access the hosts file, use terminal:
sudo pico /etc/hosts
..and enter your password where required.

Then enter the following to the end of your hosts file:
127.0.0.1 site1.co.uk www.site1.co.uk
127.0.0.1 site2.co.uk www.site2.co.uk

Then finally in terminal, you need to flush your dns cache so that your browser will use the new settings we just entered above:
sudo dscacheutil -flushcache

Finally, go in to the MAMP directory > conf > apache and edit httpd.conf, adding the following to the bottom:

NameVirtualHost *:80

<virtualHost *:80>
ServerName site1.co.uk
ServerAlias www.site1.co.uk
DocumentRoot “/Users/homefolder/Sites/site1/”
</VirtualHost>

<virtualHost *:80>
ServerName www.site2.co.uk
ServerAlias subdomain.site2.co.uk
DocumentRoot “/Users/homefolder/Sites/site2/”
</VirtualHost>

Save and close the file and then restart MAMP to load the new config changes. You should now be able to view all your sites in any browser on your machine!

It’s also just as easy to configure SSL in MAMP.


Published on

in

by

Tags:

2 responses to “MAMP (LAMP) for Mac – Hosting Multiple Sites (without the pro version)”

  1. JP avatar

    This is just what I was looking for. Very concise and very helpful.

    This is a good article on how to edit your hosts on Mac OSX

  2. […] It also covers editing your hosts file and setting up virtual hosts – useful if you are a first timer at this and something I have previously covered. […]

Leave a Reply

Your email address will not be published. Required fields are marked *