Blog Archives

Setting up a VirtualHost in MAMP


If you’ve installed a MAMP dev environment and have found the instructions you’ve read elsewhere for setting up a virtual host on port :80 aren’t working, the following should get you sorted.

1. First of all, make sure Mountain Lion’s not running Apache separately from MAMP. To do so, open, and copy/paste this into the Terminal window:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

(that’s all one line!)

Enter your admin password when prompted. Be aware that it will be invisible as you type, so type carefully. If you get an error message that says “Sorry, try again”, then indeed, try again. Only type more carefully this time! :D. On the other hand, if Terminal just returns the prompt after you hit ‘return’ or reports ‘Nothing to unload’ then you’re good to go to Step 2.

2. Assuming that you want to call your virtual host site ‘mytest’, then add to the last line of the /etc/hosts file: mytest


3. That’s the easy part! Next, add to the end of the /Applications/MAMP/conf/apache/httpd.conf file the following text:

NameVirtualHost *

<VirtualHost *>

DocumentRoot /Applications/MAMP/htdocs

ServerName localhost


<VirtualHost *>

DocumentRoot /Users/shortusername/Sites/mytest

ServerName mytest


Note that there are quote marks around both DocumentRoot filepaths. Also, be sure to change the items highlighted in red to reflect your own shortuser name and site name.

4. Go into your Home folder in the Finder, and create a folder called ~/Sites/mytest/ (before creating the ‘mytest’ folder, you may need to create the parent folder ‘Sites’ if it doesn’t already exist).

5. Create an ‘index.html’ file inside ~/Sites/mytest/ that looks something like this:

<!DOCTYPE html>
<p>My virtual host site is up!</p>

6. Finally, be sure to restart the MAMP servers and you should be up and running! 🙂

MAMP Documentation
For further help with MAMP, please see the documentation here.

Learn Ruby on the Mac

flush DNS Cache in Lion

If you need to flush the DNS cache in Mac OS X, be aware that the commands for this have changed through successive OSs, including Lion.

Flushing the cache is sometimes a good idea if you are unable to reach a site that you know is live but keeps returning an error (you can check whether a site is live for others by typing its address here: Down for everyone or just me?).

You can download my free app FastTasks that will do this (and a whole lot more! 🙂 ) for you without you needing to mess around on the command line. However, if you want to do it manually, then open Terminal (Applications > Utilities > and use the appropriate command for your operating system:

In Tiger
lookupd -flushcache

In Leopard / Snow Leopard
dscacheutil -flushcache

In Lion and Mountain Lion
sudo killall -HUP mDNSResponder

With Lion, you’ll have to follow the command with your Admin password, which will be invisible when you type it.

Related Posts
FastTasks – a utility for common terminal tasks

%d bloggers like this: