0% found this document useful (0 votes)
100 views

Quick and Dirty Local Domain Names For MAMP

This document provides instructions for setting up local domain names for sites running on MAMP on a Mac. It involves: 1) Editing the hosts file to map domain names like my-site.dev to 127.0.0.1. 2) Creating folders for each site in the MAMP htdocs directory matching the domain names. 3) Enabling virtual hosts in the Apache configuration to route requests based on domain name to the correct folder. 4) Configuring the Apache listen port and enabling the virtual host includes. Once completed, sites can be accessed by domain name instead of subfolder like http://my-site.dev.

Uploaded by

Dewa Wd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Quick and Dirty Local Domain Names For MAMP

This document provides instructions for setting up local domain names for sites running on MAMP on a Mac. It involves: 1) Editing the hosts file to map domain names like my-site.dev to 127.0.0.1. 2) Creating folders for each site in the MAMP htdocs directory matching the domain names. 3) Enabling virtual hosts in the Apache configuration to route requests based on domain name to the correct folder. 4) Configuring the Apache listen port and enabling the virtual host includes. Once completed, sites can be accessed by domain name instead of subfolder like http://my-site.dev.

Uploaded by

Dewa Wd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Quick and Dirty Local Domain Names for MAMP 4/16/16, 7:56 AM

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.

A few assumptions I am making:

You are running MAMP basic/free/non-pro with default settings


All of the sites you want domains for are in the same directory

Step 1 - Edit the hosts File


Open up your hosts file in your text editor. The file is located at:

/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

hosts hosted with ❤ by GitHub view raw

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

Step 2 - Create the Website Folder


Open up the MAMP->Preferences->Apache settings pane and make note of the Document Root path.
The default path may be

/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.

Step 3 - Enable Virtual Hosts in Apache


There is specific file for Apache that handles virtual hosts in:

/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

25 # match a ServerName or ServerAlias in any <VirtualHost> block.


26 #
27 <VirtualHost *:80>

28 UseCanonicalName Off
29 VirtualDocumentRoot /Applications/MAMP/htdocs/%0
30 </VirtualHost>

httpd-vhosts.conf hosted with ❤ by GitHub view raw

Make sure the VirtualDocumentRoot is the same path as the Document Root path you found in Step 2,
but that it ends with /%0.

Step 4 - Edit Main Apache httpd.conf File


By default Apache will listen to port 8888 in MAMP. However, we want to be able to visit http://my-
site.dev and not http://my-site.dev:8888, but we still want to leave port 8888 available for sub-folder
sites and the built-in MAMP settings site running at http://localhost:8888/MAMP/. This turns out to be a
very each change. We need to edit the main Apache config file located in:

/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

httpd.conf hosted with ❤ by GitHub view raw

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

Published 09 Nov 2012

http://blainsmith.com/articles/quick-and-dirty-local-domain-names-for-mamp Page 4 of 4

You might also like