Using MAMP as a Local Development Server

Having spent the last four hours knee deep in DNS, Apache and everywhere in-between I feel this information needs to be shared.

MAMP application icon. The simple web server for OS X.

I will start off by explaining my requirements. I am thinking of buying a Mac Pro to use as my main machine and to replace the Linux server we currently have setup in the corner of the office. If the Mac Pro is going to replace the Linux box it needs to provide us with a web server (as well as file sharing, media sharing etc) and the web server needs to be accessible over the local network to all other machines in the office. Our Linux box is serving us well but I see an opportunity to merge two computers into one; making for a greener office and hopefully it will be a little easier to manage (I am far more comfortable in OS X than ClarkConnect). We call our Linux machine “tux”, it has its own DNS server that means we can access it over the network at tux.lan. It works well but one of my issues with it has been having to install websites into sub-directories. For example our local toggle website sits at tux.lan/ Because our local sites do not live in a root web folder our local sites can have a number of differences compared to the live sites, these differences mean we have to be careful when deploying changes.

I have spent today looking at ways I can use the standard install of OSX to act as a web server. Although OS X comes with Apache built in, one of the simplest ways to get PHP, MySQL and Apache is to use MAMP. I have been using MAMP for a number of years and love the fact it is expendable and not deeply integrated into the system. If I want to change PHP version I can do so at the touch of a button and if it goes wrong I can copy a new version over the top. So how do we share MAMP over the local network with nice (virtual hostey) URLs like:

You Will Need:

I am going to assume you have a few things in place:

  1. You are running OS X 10.5+
  2. Your Mac has a fixed IP address on your local network (e.g.
  3. You have installed MAMP and your document root is your OSX sites folder
  4. You can use Terminal

The next couple of steps were modified from, which is the closest tutorial I could find to what I was trying to achieve. The main difference here is that we want this to work across the local network and not just on the one local machine.

BIND – The Hidden OS X DNS Server

A DNS server converts a name ( to an IP address ( – it basically means we do not have to remember IP addresses for the sites we want to visit. We need to enable the DNS server on our OSX machine so when we enter a local URL ( it looks for the website on the local server (which lives at I am not a DNS expert but following these steps did the trick for me.

Setup rndc

Open up terminal and get into root: sudo -s
Generate the config file for ‘rndc’: rndc-confgen > /etc/rndc.conf
Copy a key to the newly created file: head -n 6 /etc/rndc.conf > /etc/rndc.key

Create your DNS Zone File

DNS zones are created via files in /var/named. Create a new file in there called and fill it with this:

; BIND data file for dev sites
$TTL 604800
@ IN SOA dev. (
2008101920 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
@ IN NS dev.
@ IN A
*.dev. 14400 IN A

You will have to replace the IP address ( with the IP address of your Mac on the local network, remember this should be a fixed IP to ensure it keeps working.

Configure named.conf

Open /etc/named.conf. The first thing you want to do here is to show named where to get its DNS info (for the rest of the internet), it is probably best to use the OpenDNS servers. Scroll through this file until you see an options section with the line: directory “/var/named”; – just after this paste the following code:

forwarders {;;

Next we need to add a reference to the zone file we created a minute ago. There is a localhost section already in /etc/named.conf, find it and post the following code below it:

zone "dev" IN {
    type master;
    file "";

Getting DNS to start with your Mac

Open the LaunchDaemon plist file (/System/Library/LaunchDaemons/org.isc.named.plist) and look for the first instance of the word ‘true’ and change it to ‘false’. It should appear just under the word ‘disabled’. You can now load it using the following terminal command:

sudo launchctl load /System/Library/LaunchDaemons/org.isc.named.plist

The DNS server should now be up and running on your machine, you will need to tell other machines on your network and the Mac itself to look at this IP address for DNS. In system preferences -> network -> add ‘’ to the list of DNS servers (for the server itself) and for other machines on the network add ‘’ to the list of DNS servers. The other machines on the network will now look to this IP address when you first type in a URL into your browser.

Setup MAMP

Now that the DNS stuff is out of the way, it’s just a matter of setting that magic directive in your Apache conf file. The directive is called VirtualDocumentRoot. You need to navigate to the MAMP folder (/Applications/MAMP/conf/apache) and open up httpd.conf in a text editor of your choice. Search the file for “Virtual hosts” and uncomment the line just below:

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

Next open the httpd-vhost.conf file in the extra folder, scroll to the very bottom of the file and add the following code:


    VirtualDocumentRoot /Users/YOURUSERNAME/Sites/%-2+/

The VirtualDocumentRoot is an interpolated path for finding your sites. ‘%-2+’ means everything before the .dev. So: would load files from /Users/YOURUSERNAME/Sites/example/. If MAMP was running you should now re-start Apache and visiting in your browser should bring up a 404 (unless of course you have a folder called example in your sites folder). Did it work?

Hitting Problems

I had a number of issues getting this to work across the network and during that time I was running quite a few commands to get rndc to restart without having to reboot my machine every time I made a change. At first I could not get rndc to listen to any of my commands, searching Google once more I found a handy forum tip suggesting the issue might be related to port numbers. I suggest you follow these few extra steps to resolve the issue:

Open up terminal and run the following: sudo nano /etc/rndc.conf – look for the options at the top of the file and make sure the default port is set to 54. Save (ctrl-x, Y, Enter) and you should now be able to use the the command line to interface with rndc.

Useful Commands

Whilst working through the steps above I came across a number of handy command line tools that you might find useful too:

nslookup dev : nslookup will interactively find MX and other records. I used this on network machines to see if they correctly identified the Mac as the .dev server. dscacheutil -flushcache : OSX has a tendency to cache DNS, this flushes the cache so you can check your changes. rndc reload : This reloaded any changes I made to my DNS zone files.

So that brings me to the end of this tutorial, having successfully tested this on my Mac laptop I am now one step closer to making a decision about the Mac Pro. How did you get on?

p.s. If you follow these steps and consequently have issues with PHP’s $_SERVER['DOCUMENT_ROOT'] variable. You might wish to follow the advice here. Apache does not play well with document roots and virtual hosts.