Tutorial: Launching MAMP Silently on Startup

August 25th, 2008

MAMP Web ServerMAMP is a great tool for running and managing a development server when you require more than the basic PHP configuration included with Leopard. However, getting the web server to run typically involves launching MAMP, entering your root password, and quitting MAMP.

This tutorial walks through the simple steps needed to launch MAMP silently on startup so that you do not have to enter your root password every time.

The issue with MAMP is that launching Apache must be done as root, so there’s no way to simply add MAMP to your startup items via the system’s Accounts Preferences in a way that will launch the app silently. But you don’t need to. Here’s the deal: MAMP’s launcher is just a pretty UI that opens a shell script that, in turn, launches MAMP’s Apache and MySQL servers.

You can set up launch daemons that do the exact same thing without the need to launch MAMP or enter a password.

Step 1: Create the Start-up Items

Open up your favorite text editor and paste the following into an empty document:

Create another for the MySQL start-up item:

Be sure to replace “YOUR_USERNAME” with the username for your account.

Step 2: Save the Files

Save this file as (or move the file to) /Library/LaunchDaemons/info.mamp.start.apache.plist and /Library/LaunchDaemons/info.mamp.start.mysql.plist, respectively.

Step 3: Set Permissions

If you try to launch the daemons at the moment, you’ll get a “dubious permissions” error. To correct this problem, you’ll need to change your permissions.

In your terminal, type:

You’re done! Reboot your computer and test that your development server is running as expected by opening a served page in your browser.

  • http://www.joshfraser.com Josh Fraser

    I’ve been wanting to do this for a long time. Apache is starting up fine, but MYSQL seems to be having some problems. I did everything you said and am getting this error message:

    Could not select database: Can’t connect to local MySQL server through socket ‘/Applications/MAMP/tmp/mysql/mysql.sock’ (2)

    Any idea what’s going on? Thanks for your help!

  • http://www.stringersites.com sstringer

    @Josh Fraser – You’ll want to check out this post that deals with the mysql.sock error:

    http://bit.ly/5ikum

  • http://www.stringersites.com sstringer

    @Josh Fraser – Sorry about that. I accidentally linked to the admin screen for that post. Try this:

    http://bit.ly/1tQ4GI

  • Sheludkov

    Hi,
    & thanks for a great tutorial.

    Also for me Apache is starting up fine but MYSQL not. I get the message: “Error establishing a database connection” and /Applications/MAMP/db/mysql/Sheludkov.local.err says:

    081006 09:52:20 mysqld started
    /Applications/MAMP/Library/libexec/mysqld: Too many arguments (first extra is ‘‚Äìport=3306′).
    Use –help to get a list of available options
    081006 09:52:20 mysqld ended

    ..?

    :S

  • http://www.stringersites.com sstringer

    @ Sheludkov – The message sounds like you have a typo in your MySQL launch script arguments. Try launching it via Terminal to work out the kinks, and then paste it in.

  • Sheludkov

    I had been copied theMySQL start-up item directly from this page. The argumets are like
    this: –port=3306.
    I just changed “-” to “–” (like –port=3306) and it works now :)

    Thanks a lot!
    :S

  • http://www.giantrobot.co.nz/ Chris Burgess

    PS.

    1. Thanks heaps for the helpful post!

    2. Option to preview comments is useful when people are posting code. If I could preview comments, I wouldn’t be about to repeat the function name in the next sentence, because I’d know whether or not I can hyperlink here.

    3. The culprit function is wptexturize(), cough, wptexturize().

    4. Pretty sure you can disable this; wptexturize() is the same function which swaps normal, straight quote marks for “this kind”, making various other code blocks not copy and paste right.

  • http://www.giantrobot.co.nz/ Chris Burgess

    Hmm – ok, my first comment didn’t appear!

    In your code block above for info.mamp.mysqld.plist, the double-hyphens have been replaced with longdashes by wptexturize().

    I can’t type HTML entities here, but you should have two of this character: -

    rather than one of this character: –

    The latter won’t work. This is why Sheludkov had trouble with the code you’ve posted.

    Cheers

  • http://www.giantrobot.co.nz/ Chris Burgess

    So, remove the spaces from these

    – -port=3306

    – -pidfile==/Applications/MAMP/tmp/mysql/mysql.pid

    etc etc

  • dwenaus

    C’MON. This post needs to be fixed. The essential information that chris posted at the end needs to be incorporated into the body of the post. Rather than post the code in the body of the text where wordpress is screwing up the double dash turning it into an em dash. link to code at another location (like http://snipt.net/). People shouldn’t have to read all the comments to figure out what is going on here.

  • http://www.stringersites.com sstringer

    My apologies to everyone. Long story short, I’ve been on other projects and missed your comments that WP was rewriting my code.

    Many thanks to @dwenaus for the good top in hosting the code snippets on snipt.net.

    Your comments about posting code in the comments are well taken. I’ll look into finding a better commenting plugin that doesn’t sacrifice site security.

    Cheers,
    Steve

  • jon

    this worked great for about 3 months. Then all of a sudden the apache script is not woriking though MySQL still starts fine. I can't think of any changes to my system.

  • millipo21
  • jon

    I have desided that the problem is that MAMP sucks, MAMP and MACs are for amatures.

  • http://www.stringersites.com Steve Stringer

    You are certainly entitled to your opinion, although I'll respectfully disagree. I know no professional web developers that uses Windows as their primary platform, and my personal experience is that developing on Windows is nothing but a world of pain and frustration. But that's just one person's opinion. =)

  • jon

    I agree, running window these days is like running a marathon in a swamp. What I was really getting at was that MAMP does not work well at least on my PPC mac. I finally gave up and installed apache, MySQL and PHP5 the old fashioned way like I would on Linux.

  • jon

    I have desided that the problem is that MAMP sucks, MAMP and MACs are for amatures.

  • http://www.stringersites.com Steve Stringer

    You are certainly entitled to your opinion, although I'll respectfully disagree. I know no professional web developers that uses Windows as their primary platform, and my personal experience is that developing on Windows is nothing but a world of pain and frustration. But that's just one person's opinion. =)

  • jon

    I agree, running window these days is like running a marathon in a swamp. What I was really getting at was that MAMP does not work well at least on my PPC mac. I finally gave up and installed apache, MySQL and PHP5 the old fashioned way like I would on Linux.

  • http://www.easysitebuild.com/ website builder

    Looks like this is a pretty good tool. Thank you for sharing the script images. :)

  • http://www.icusa.net/ Naples web design

    I think most of the PHP programmers used this kind of tool because as I see it based on the description of what this tool can do. It's good to have a tool wherein it does a good managing process especially when it deals already with those code scripts.

  • echo

    Thanks, worked flawlessly to have mamp servers auto launch on startup!

  • http://www.idcreate.net Cheap Web Design Edinburgh

    very good article

    keep it going

  • http://security-wire.com/01/how-to-remove-disk-optimizer-fake-security-program.html remove disk optimizer

    Your article is really helpful!

  • Lhridley

    Great article! Worked perfectly!

  • Felipe Vaz

    thank you VERY much for this — despite the article being 3 yrs old, this is the only method I found to work properly on my environment (OS X Lion, MAMP not PRO)

    I didn’t even had to tweak anything other than filling my username to get it working

  • echo

    I’ve used this for a long time, successfully launching *non* Pro MAMP on startup, really have appreciated it, thanks! Since updating to MAMP v2, now on 2.0.3, the plist for starting apache no longer works, only mysql starts. Does anyone know what could have changed in version 2 and how to adjust this launch daemon plist?

  • echo

    I finally got the start apache daemon working by adding as the first key, before Label -
    Disabled 

  • echo

    the comments corrected the tag, that was actually a self closing tag – false/

  • echo

    Sorry for all the posts, that wasn’t it and don’t know how that worked once as a fluke. I was getting the “mod_unique_id: unable to find IPv4 address” error, and entering my machine’s xxx.local in my hosts file fixed it.

  • sergio eurico

    Thank you!! This works perfect on my Mountain Lion 10.8.3