Setting up URL aliases for local development with MAMP

This is guide on how to setup a domain aliases when doing local development using MAMP. By this I mean rather than accessing the site by something like http://localhost/my-site you set up an alias like

Personally I create URL aliases for all local developments as it is fairly straight forward and gets around the problem of having your site appear in a 'sub-folder'. 

For the example lets assume that you have a locally hosted site in a folder called 'mySite' located in your home folder:

  • ~/www   (eg. /Users/joebloggs/www)

With the above you would access your site at something like: http://localhost:8888/mysite

To make it so that you can view your site at follow these steps... 

1) Edit 'httpd.conf' file

Locate and open this file using a text editor. The file can be found at the below location if MAMP is installed in the default Applications location.

  • /Applications/MAMP/conf/apache/httpd.conf

Uncomment virtual hosts include path in 'httpd.conf' file

Search for the '# Virtual hosts' entry and uncomment the line 'Include conf/extra/httpd-vhosts.conf'. This will tell Apache to include the file where we will add our virtual host entries.

# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Set document root folder

If you don't use the default document root (/Applications/MAMP/htdocs) then change this to point to where your sites code sits. For example I keep all my sites within a 'www' folder under my user home directory (justin), eg.

DocumentRoot "/Users/justin/www"

Having done that you need to change this line which appears shortly after the DocumentRoot:

<Directory "/Applications/MAMP/htdocs">

So that would become something like:

<Directory "/Users/justin/www">

Change the default port

Rather than using the MAMP default (8888) I like to set my port to 80. This way you don't have to reference your sites using something like http://localhost:8888, but can use just http://localhost. Change both of these entries in the httpd.conf from using 8888 to just 80.

Listen 80
ServerName localhost:80

3) Edit 'httpd-vhosts.conf' file

Locate and open this file using a text editor like notepad. This is where we will set the virtual host names.

  • /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf    

4) Add a VirtualHost entry to your 'httpd-vhosts.conf' file

Paste this code into the bottom of the httpd-vhosts.conf file. Change the references to 'mySite' to match your settings.
Incidentally your server name doesn't have to be in the format, you could use something like local.mysite which you would then visit in your browser at http://local.mysite (just make sure that the URL matches the one you add to your hosts file in the next step).

<VirtualHost *:80>
	     # The name to respond to
	     # Folder where the files live
	     DocumentRoot "c:/wamp/www/mySite"
	     # A few helpful settings...
	     <Directory "c:/wamp/www/mySite>
	    allow from all
	    order allow,deny
	     # Enables .htaccess files for this site
	     AllowOverride All
	     # Apache will look for these two files, in this order, if no file is specified in the URL
	     DirectoryIndex index.html index.php

5) Edit your 'hosts' file

On a Mac this can be found at: /private/etc/hosts, and on Windows at: C:\Windows\System32\drivers\etc\hosts
Again just open this file using something like Notepad, and add an entry like this:

6) Restart your local server

Restart Apache on MAMP and refresh your browser - with some browsers you may need to close and re-open it. Now when you visit you will be seeing your locally hosted site via it's domain alias.

Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.