Quick and Dirty Local Domain Names For MAMP
Quick and Dirty Local Domain Names For MAMP
More often than not I've been needing to run web projects under their own domain instead of the simple
sub-folder method. One major advantage to developing this way is deployment to production only has to
rely on the domain name instead of sub-folder paths which can get annoying to work with. Since I have
always leaned towards MAMP as my goto stack for development on my Mac I figured I can just tweak
minor pieces of it without having to set up a custom stack.
Going through these steps will allow you to enter http://my-blog.dev into your browser and it will
respond as if it had its own domain.
Now, for all you non-techie designers out there, fear not. We are making minor text file changes which
can be undone.
/etc/hosts
At the end of that file add the sites you wish to respond. You will need to enter 1 line per site you want in
the following format:
127.0.0.1 my-site.dev
Make note of the name my-site.dev because will be using it later on. I have included a few more
examples of what can be put into the hosts file.
1 # Custom Hosts
2 127.0.0.1 wordpress.dev
3 127.0.0.1 drupal.dev
4 127.0.0.1 webapp-a.dev
5 127.0.0.1 webapp-b.dev
6 #127.0.0.1 NEW-SITE.dev
http://blainsmith.com/articles/quick-and-dirty-local-domain-names-for-mamp Page 1 of 4
Quick and Dirty Local Domain Names for MAMP 4/16/16, 7:56 AM
/Applictions/MAMP/htdocs
Now create your new website folder there called my-site.dev so your new site should be living in:
/Applictions/MAMP/htdocs/my-site.dev
It is important that you name the folder the same name you used in Step 1.
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Open that file and change it to the version I included for you here:
1 #
2 # Virtual Hosts
3 #
4 # If you want to maintain multiple domains/hostnames on your
5 # machine you can setup VirtualHost containers for them. Most configurations
6 # use only name-based virtual hosts so the server doesn't need to worry about
7 # IP addresses. This is indicated by the asterisks in the directives below.
8 #
9 # Please see the documentation at
10 # <URL:http://httpd.apache.org/docs/2.2/vhosts/>
11 # for further details before you try to setup virtual hosts.
12 #
13 # You may use the command line option '-S' to verify your virtual host
14 # configuration.
15
16 #
17 # Use name-based virtual hosting.
18 #
19 NameVirtualHost *:80
20
21 #
22 # VirtualHost example:
23 # Almost any Apache directive may go into a VirtualHost container.
24 # The first VirtualHost section is used for all requests that do not
http://blainsmith.com/articles/quick-and-dirty-local-domain-names-for-mamp Page 2 of 4
Quick and Dirty Local Domain Names for MAMP 4/16/16, 7:56 AM
28 UseCanonicalName Off
29 VirtualDocumentRoot /Applications/MAMP/htdocs/%0
30 </VirtualHost>
Make sure the VirtualDocumentRoot is the same path as the Document Root path you found in Step 2,
but that it ends with /%0.
/Applications/MAMP/conf/apache/httpd.conf
Also, while we have this file open we are going to uncomment a line to make sure Apache loads the
virtual host settings we set up in Step 3.
You will need to add Listen 80 above the Listen 8888 line in your own file and uncomment the line
below # Virtual hosts. Here is a snippet of the httpd.conf file and how yours should look once you make
those 2 changes.
1 #
2 # Listen: Allows you to bind Apache to specific IP addresses and/or
3 # ports, instead of the default. See also the <VirtualHost>
4 # directive.
5 #
6 # Change this to Listen on specific IP addresses as shown below to
7 # prevent Apache from glomming onto all bound IP addresses.
8 #
9 #Listen 12.34.56.78:80
10 Listen 80
11 Listen 8888
12
13 # MORE CONFIG SETTINGS...
14
15 # Virtual hosts
16 Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
http://blainsmith.com/articles/quick-and-dirty-local-domain-names-for-mamp Page 3 of 4
Quick and Dirty Local Domain Names for MAMP 4/16/16, 7:56 AM
Once you have all of these changed and saved just stop and start MAMP and you should be able to visit
http://my-site.dev in your browser. Now to add more sites just repeat Steps 1 & 2. You can even set up
existing sites this way as well.
I hope this helps developers and designers alike. It is simple and doesn't require paying for MAMP Pro.
Written by
Blain Smith
http://blainsmith.com/articles/quick-and-dirty-local-domain-names-for-mamp Page 4 of 4