Supercharge Your MAMP Environment

By on May 16, 2008 12:13 am

MAMP is an easy way to get a basic MAMP (Mac, Apache, MySQL, PHP) environment running. Each package in the stack is configured such that it’s easy to drop the MAMP directory into /Applications and serve up a database-backed PHP site.

Much of this simplicity is baked in at compile time so you can deal with the entire stack as you would a regular Mac OS X app bundle (e.g. by dragging it around between networked machines to replicate it) rather than having to coordinate the components yourself. However, the default configuration can be a touch limiting, so a little surgery is in order. We can set it up to be a little more powerful, yet retain its friendliness.

Before you install: The normal .dmg on the MAMP download site is a binary-only setup. For tasks that are more involved than changing confuration files or creating symbolic links, you’ll find it handy to have the source available; source+binary packages are at the bottom of the download page. I’d recommend installing that even if you don’t plan on needing the source right away; it’s a lot easier to ignore the extra files than it is to try to add them in later.

1. Use Standard Ports

MAMP GUI Ports tabThis isn’t absolutely required, of course, but it can make housekeeping simpler—and at the very least, your URLs prettier—if you configure Apache and MySQL to use the standard ports (80 and 3306, respectively) rather than the MAMP defaults of 8888 and 8889. Lots of packages that you might install in your PHP environment default to talking to MySQL on port 3306, so doing this once keeps you from having to specifically configure everything else.

The easiest way to accomplish this is to simply use the MAMP GUI program provided in /Applications/MAMP/, click the Preferences button, and visit the Ports tab. What it does is change the port numbers in the Listen directive in httpd.conf and the invocation of mysqld_safe in /Applications/MAMP/bin/

Moving Apache to port 80 will require that you run it as root or via sudo. Keep that in mind for later when we automate the startup.

2. Set Up Virtual Hosts

Getting more than one site working is pretty simple. Assuming you’ve installed MAMP at the default location of /Applications/MAMP:

  1. Create a directory /Applications/MAMP/conf/apache/vhosts. Put any virtual host definitions in this directory (see below for a simple virtual host).
    mkdir /Applications/MAMP/conf/apache/vhosts
  2. Open /Applications/MAMP/conf/apache/httpd.conf and add this to the end:
    NameVirtualHost *:80
    Include /Applications/MAMP/conf/apache/vhosts/*.conf
  3. Restart Apache. That’s it!
    sudo /Applications/MAMP/bin/apache2/bin/apachectl restart

    If you didn’t switch to port 80, you can drop the sudo, by the way.

Note that the Include statement makes it easy to turn virtual hosts on and off: just rename files in the vhosts directory. Use a .conf extension to enable a file; remove the extension to disable it. Feel free to use your own fancy expression here; restart MAMP every time to make the changes take effect.

Generally, other than whatever you set up as your filename inclusion expression above, the filenames of the vhost definitions don’t matter. One exception is that the first one processed becomes the default site served up when you hit or localhost. Prefix the filename of the one you want to be the default site with something like 000- to make sure it comes first alphabetically.

Also note, of course, that if you don’t have a local DNS server, you’ll need to set up a line in /etc/hosts for each virtual host. On Leopard, that works out of the box. On Tiger, you have to make sure your lookupd is set up to read from /etc/hosts before hitting DNS.

Sample Virtual Host (/Applications/MAMP/conf/apache/vhosts/vhost.local.conf)

Here’s a trivial virtual host. Probably 90% of mine are just slight variations on this.

    ServerName vhost.local
    DocumentRoot /Applications/MAMP/htdocs/vhost.local/
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

If your project doesn’t have a build process that dumps the published files to your virtual host’s DocumentRoot, sometimes it’s useful to create the DocumentRoot as a symbolic link that points to your working copy of the project’s version control repository. Then you can just work from there without having to publish your files out to some directory just so you can test things.

3. Run at Startup via launchd

I admit it: I’m lazy. I originally set up my MAMP GUI program to run as a login item for my account in System Preferences, but I got tired of having to switch to it so I could quit it and not have to look at it. My eyesight is precious; heaven forbid I waste it—not to mention the three whole seconds of my time—doing that! Far more productive would be to spend a few minutes learning how to set it up to run automatically, in a Leopardy way.

As Apple’s documentation on System Startup Programming Topics describes, the Leopardy way to start services automatically is via launchd (and the Tigerish way is via StartupItems, also covered in that link). Essentially, you create a .plist definition for each service you wish to handle, then register it with the system (or just reboot). In our case, our two services are Apache and MySQL, so we’ll create a separate file for each. All we’re doing is plistification of the regular shell scripts MAMP uses for startup.


Put the following in /Library/LaunchDaemons/



Create /Library/LaunchDaemons/ thusly:


Make sure you put your username in there! For MySQL we’re running as you rather than root; it works better if we do that. Actually, the MAMP package is set up to be run as a normal user already; the only reason we are doing it this way here is so Apache has access to port 80 from our port change above. If you’re using ports above 1024, you could probably tighten things up by creating these as “agents” rather than “daemons”, but I don’t want to get lost in Mac system startup minutiae. Their docs (including the man pages for launchd and launchd.plist) cover it all.

There, by doing this you’ve saved yourself a few seconds per boot. Depending on how long you go between boots, I figure I’ve saved you at least a minute or two per year! In a couple of years when you break even on the time you just spent setting this up, you’ll thank me for all of the free time.

4. Proxy Real Data

Often a web app’s architecture is designed around a REST or RPC service to shuttle data back and forth to the client side. In such cases, one useful technique Apache makes available is to use mod_proxy to let you transparently connect to some shared development server or staging data, without needing to configure your local build to know about the separate environment. You could even proxy production data if you wanted; just be careful not to clobber it!

Anyway, say your project has a REST endpoint at /rest. Working from our trivial virtual host from above, you do this in your httpd.conf:

    ServerName vhost.local
    DocumentRoot /Applications/MAMP/htdocs/vhost.local/
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

    # here the magic happens
    ProxyPass /rest

Voila! Now any requests made to http://vhost.local/rest get forwarded to, and you can use real data without having to do a typical dump/restore cycle.

Oh, and if you’re going to do something like this, take all the necessary precautions so you don’t create an open proxy for the whole world to use.

5. Create a Friendlier DocumentRoot

It doesn’t take long to get tired of putting files in /Applications/MAMP/htdocs, MAMP’s default Apache DocumentRoot, to serve them up. Symbolic links to the rescue! Do this:

ln -s /Applications/MAMP/conf/apache/vhosts/ ~/Sites/conf
ln -s /Applications/MAMP/htdocs/ ~/Sites/vhosts

Now you can get to your virtual hosts (and their configuration files) through your home directory.

Of course, if you’re not using virtual hosts, you could just symlink the ~/Sites directory directly to MAMP’s DocumentRoot. Or just change the DocumentRoot altogether. However you like to work.

6. Get PEAR Working

MAMP ships with a PEAR environment, but you have to nudge it a bit to work completely. The /Applications/MAMP/bin/php5/lib/php directory is already in the include_path in php.ini, so using PEAR from PHP works out of the box, but the pear binary isn’t in your $PATH by default. Add a line to your ~/.profile:

export PATH=/Applications/MAMP/bin/php5/bin:$PATH

Now you can do things like pear upgrade-all to stay on top of new developments.

7. Relocate Your Databases For (Probably Slight) Performance

If you 1) have more than one disk in your system, and 2) don’t mind losing the application bundle-ness of your MAMP environment, you can get a bit of performance increase by moving your databases to a disk other than your regular boot volume. It most likely won’t be anything to write home about, but I know I’ve noticed an improvement when working on projects with multi-gigabyte databases.

MAMP comes with MySQL and SQLite, both of which store their data in /Applications/MAMP/db. Simply move the db directory to another disk and create a symbolic link in its place, pointing to the new location. For example, mine was:

mv /Applications/MAMP/db /Volumes/dev01/
ln -s /Volumes/dev01/db/ /Applications/MAMP/db

Don’t forget to restart MAMP.

8. Install mod_python

Out of the box, MAMP is designed around PHP & MySQL/SQLite; however, it’s not limited to that. If you want to develop with Python rather than PHP, adding mod_python can really make your environment sing. You need the MAMP source for this, so hopefully you took my advice earlier and installed the full distribution rather than the binary-only package.

  1. Install the module.
    • Binary download: If you’re feeling lucky and boisterous, you can try the precompiled mod_python I built for my system (MAMP 1.7.1, Apache 2.0.59, mod_python 3.3.1). Install it with:
      tar xzf MAMP-1.7.1_mod_python-3.3.1.tar.gz     \
          -C /Applications/MAMP/Library

      Then, skip to step 2.

    • Source download: If you’d rather build from source yourself (or my build doesn’t work for you), download the mod_python source. Build it like so:
      # this symlink makes the configure script work
      sudo ln -s /Applications/MAMP/Library/ /usr/local/apache2
      # MAMPified build
      ./configure --prefix=/Applications/MAMP/Library               \
                  --with-apxs=/Applications/MAMP/Library/bin/apxs   \
      make install
  2. At this point, mod_python will be ready to go, but we could do with a bit more system integration. It’s nice to be able to easy_install something from the command line and have it not only automatically available to mod_python, but also living inside the MAMP application bundle. Let’s configure that:
    • One way is to use a symbolic link to point your user site-packages directory at MAMP’s new one:
      mkdir -p ~/Library/Python/2.5
      ln -s /Applications/MAMP/Library/site-packages/   \
    • Alternatively, based on the Easy Install documentation, you can put this in ~/.pydistutils.cfg:
      install_lib = /Applications/MAMP/Library/site-packages
      install_scripts = /Applications/MAMP/Library/bin

    I have both of these set up. Don’t ask me why; I can’t remember if I needed it or if it’s just left over from when I was trying different configurations out. If you do the latter but not the former, make sure to add /Applications/MAMP/Library/site-packages to your $PYTHONPATH.

  3. Finally, Add a line to /Applications/MAMP/conf/apache/httpd.conf:
    LoadModule python_module modules/
  4. Extra finally, restart MAMP.


The beauty of MAMP is that it’s a regular LAMP stack, just Mac-ish. It’s self-contained like a normal Mac application, but once you figure out where everything is, it’s easy to customize just like you would a regular LAMP stack. Just don’t go too crazy, or else you may as well just use fink!

P.S.: Here are the support files for this post:


  • Vasko

    great article, thanx for the precompiled mod_python.

  • laura landy

    Store site files in /Sites question:

    I am new to this back-end stuff, but finally managed to get MAMP (and Headdress) installed and working in order to create a test site for WordPress (course, now I can used it for my other sites, too, once I upgrade to Pro). You describe a way to avoid storing your files within the MAMP folder, which I’d like to do so that all my websites are in the default Sites folder.

    However, I don’t know how to use the command line. At the risk of being dumped on because I don’t want to be hardcore and learn all that right now(another time, sure), I’d like to do it through the GUI. Is there a way? Or can you quickly tell me how to access the command line in OS x?



  • Hi Laura,

    The MAMP GUI admin program’s Apache tab allows you to specify the Document Root of your choice, so if you’re just developing one site (or don’t mind changing this setting every time you change which site you’re working on), this is probably the easiest way to get MAMP looking at files in your home directory.

    If you do decide to starting learning the command line, in /Applications/Utilities you’ll find a program called Terminal. That’s all you need.

  • Thanks for posting this. I just got my macbook pro and since I’ve been on a PC for years, I don’t know my way around the mac. You saved me hours of fiddling around, thanks!

  • steve mckenzie

    thank you so much for this post.

    1 great addition would be to get svn dav working with mamp :)

    that’s been something a lot of people have been wanting for a while.

    I’m not unix savy enough though.

  • steve mckenzie

    hmm… im back for another comment.

    I can’t seem to get mod_python to work.

    following your instructions, i first grabbed your precompiled but realized it didn’t have the actual .

    so i built my own with your instructions and there it is now.

    first test, i tried running a .py but realized no AddHandler was setup for it so I did that

    AddHandler mod_python .py

    however still no go.

    i then followed instructions for adding the handler from here..

    they show..

    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On

    i basically showed the 3 lines (addhandler, pythonhandler, etc..) in the big MAMP_Port_interation stuff where it defines Directory but that didn’t do it either.

    now i have a straight up AddHandler mod_python .py only and its right after where i do LoadModule.

    any ideas?

  • Hmm, I just downloaded the .tar.gz from the link above and ran it through tar tvzf, and the is the very first item in the output. If you use the tar command from the article (including the -C parameter), it should end up in /Applications/MAMP/Library/modules/

    Probably the simplest test to do is to use the mod_python.testhandler, e.g.:

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName py.local
    DocumentRoot /path/to/some/docroot
    <Location /mpinfo>
    SetHandler mod_python
    PythonHandler mod_python.testhandler

    Then hit http://py.local/mpinfo in a browser to see the diagnostic output.

    The handler you use for your development really depends on what you’re doing. For example, I have a local installation of Trac running, and it uses SetHandler mod_python, and PythonHandler trac.web.modpython_frontend. The mod_python installation itself comes with a couple of handlers (see, or you can create your own. If I had to guess, I’d say to look at the Publisher handler first.

    One annoying thing I found is that if you run Apache on port 80, the mod_python install won’t work if you run Apache as root (which the launchd suggestion in the article above does). You can’t make launchd start Apache as your regular user either, or else it won’t be able to bind to port 80. So what I do is, use launchd to start everything up, and if I’m doing any work that requires mod_python, I stop and restart Apache via sudo:

    sudo /Applications/MAMP/bin/
    sudo /Applications/MAMP/bin/

    That way it runs as me, but has the requisite root privs to use port 80. It’s tedious and halfway defeats the purpose of automating things; I consider it a work in progress. If you hit on a nicer way of getting it going, please post it here.

  • vic


    “3. Run at Startup via launchd” is not working for me. Am I right in presuming these plists are so we don’t have to put MAMP in our Login Items? I put the plists in the proper place and I also created a mysql account with a different username than root and saved that into the mysql plist and restarted the system, but alas, no autologin to MAMP. am I missing something? I know your instructions are crystal clear and yet I am stumped. can’t i just get away with using root as the username if mysql database only has a root user O_o? kthxbye.

  • Marlon

    That is a great article. Do you have any instructions for compiling mod-wsgi into MAMP? That would be greatly appreciated.

  • @vic:

    Sorry to hear it’s not working. MAMP as a package is generally designed to be run under your own OS X user account. When you say you “created a mysql account,” that sounds to me like you set up a new login account within mysql itself, and not a new OS X user account, correct? The “YOUR_USERNAME_HERE” in my instructions is intended to be the short name of your OS X user account, e.g. “rg” for me (which I specifically changed it to from the system-generated “revinguillen” when I entered my user name as “Revin Guillen”).


    I’d never done anything with mod_wsgi before, so I gave it a shot this morning. It turned out to be pretty simple. Here are the basic steps I took:

    1. Download and unpack the latest tarball from

    2. cd to the directory in which it unpacked and run ./configure

    3. In the ./configure output, I saw “checking for apxs… /Applications/MAMP/Library/bin/apxs”, which looked promising. Just to be sure of what it was doing, I opened the Makefile it generated to take a look, and sure enough: APXS = /Applications/MAMP/Library/bin/apxs, LIBEXECDIR = /Applications/MAMP/Library/modules. Also, I saw that the install target puts everything into the $(LIBEXECDIR), which is perfect. Good to go.

    4. make && make install

    5. Add the following line to /Applications/MAMP/conf/apache/httpd.conf: LoadModule wsgi_module modules/

    6. Create a simple virtual host to test things out (I also added wsgi.local to my /etc/vhosts so I could use the name; this would easily work on localhost too):

    <VirtualHost *:80>
        ServerName wsgi.local
        WSGIScriptAlias / /Users/rg/
        <Directory /Users/rg>
            Order allow,deny
            Allow from all

    7. Create a simple test script (got this from the mod_wsgi README), saving it as /Users/rg/test.wsgi so my new vhost would see it:

    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
        response_headers = [('Content-type', 'text/plain'),('Content-Length', str(len(output)))]
        start_response(status, response_headers)
        return [output]

    8. Restart Apache. To see if it loaded mod_wsgi, I did tail /Applications/MAMP/logs/apache_error.log, and saw: “Apache/2.0.59 (Unix) mod_python/3.3.1 Python/2.5.1 DAV/2 PHP/5.2.5 mod_ssl/2.0.59 OpenSSL/0.9.7l mod_wsgi/2.1-BRANCH configured — resuming normal operations”. Note that mod_wsgi is there, and the log contained no other errors. Time to test the script.

    9. Visit http://wsgi.local/test.wsgi in my browser. The “Hello World!” message showed perfectly!

  • I should note that in my mod_wsgi instructions in the comment above, in step 3 where I verified the settings created by the ./configure script; it’s likely that the reason the defaults were correct is that other configuration I’ve done over time set the system up to detect my MAMP-related installation first. If you run ./configure and don’t get APXS = /Applications/MAMP/Library/bin/apxs, LIBEXECDIR = /Applications/MAMP/Library/modules in the Makefile it generates, go right ahead and change the Makefile to match, then continue with the make && make install.

  • Jason

    I tried getting mod_wsgi to work with mamp 1.7.2 but when I use the instructions above I get this:

    ./configure –with-apxs=/Applications/MAMP/Library/bin/apxs –with-python=/usr/bin/python –with-libexecdir=/Applications/MAMP/Library/modules
    checking Apache version… cannot open /Applications/MAMP/Library/build/ No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.
    cannot open /Applications/MAMP/Library/build/ No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.
    ./configure: line 1696: /: is a directory

    /usr/bin/lipo: Can’t map input file: / ((os/kern) invalid argument)
    cannot open /Applications/MAMP/Library/build/ No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.
    configure: creating ./config.status
    config.status: error: cannot find input file:

    I think the old version of MAMP had a build directory and this new version didn’t. I also tried to point my apxs to /usr/sbin/apxs because there is one there but then after the install I try to start apache and get this:

    sudo ./
    Syntax error on line 288 of /Applications/MAMP/conf/apache/httpd.conf:
    API module structure `wsgi_module’ in file /Applications/MAMP/Library/modules/ is garbled – perhaps this is not an Apache module DSO?

    Any suggestions?

  • Dan

    Man, what a pain this is to get mod_wsgi running with MAMP. Better to go with cheap hosting.

  • Jason

    I finally got wsgi running with xampp. I had to rebuild apache 2.2 and then download the source for wsgi. I compiled the wsgi with the apache 2.2 source and copied the .so file to the xampp mods directory and it loaded. If anyone wants more details let me know and I will try to dig them up.

  • Awesome Revin, you got me set up and my previous Apache problems are gone.

    I couldn’t get MAMP to auto-launch on startup however until I looked at the Apple Docs and saw that you have to change the permission of the plist file. Owner to ‘root’ and group to ‘wheel’:

    Mac:LaunchDaemons mike$ sudo chown root:wheel “”

    I’m not using MySql, but those perms should be ok; the docs say that one is owned by you.

  • jhamrad

    Hello Revin,

    I run into troubles with the installation of mod_wsgi with MAMP 1.7.2 in spite of your clears explanations.
    It seems that the configure script is not using the good directory and when I try ‘make’ I have an error.
    Could you try to help me, perhaps it’s a simple error but I didn’t find it.
    Here is a screenshot of the output and the Makefile

    Thank you for your help
    Have a nice day!

  • Pingback: Virtual Hosts w/ MAMP - Nicholas Kreidberg | Nicholas Kreidberg()