MAMP and PHP Development on the Mac

I’ve been doing a lot of my web development lately on my macbook pro, but the problem is that I do the work locally, then have to rsync it to my Linux-based server to see the results. Not a huge deal, but a PITA. So I decided I was going to look into running the “stack” on my mbp directly, so I could do all the development locally… great for when I’m at the in-law’s place without a direct internet connection.

I’ve been reading about MAMP and XAMPP, both are providers of the “stack” for OS X (XAMPP actually also works on Linux and Windows too). I chose MAMP because it has a more recent version of PHP available (5.1.6 vs. 5.0.5 in XAMPP). I’m hoping they’ll update soon to 5.2.0 since that’s what my webserver will be running in a few months.

The problem with MAMP, however, is that you have to run the stupid MAMP application to actually start the apache and mysql daemons; it doesn’t provide support to have them started on their own at system startup. This thread on the MAMP forum gives you some clues, but not enough. For one, they set it up as an “on-demand” thing, triggered by a user login. This is fine for a desktop machine I suppose, but not so good for someone, say, running an Xserve and using MAMP as their production “stack”. So I took the info, did some fiddling, and got it to start at boot. Unfortunately, when you install MAMP (as a user), some ownership of files go to you that can’t go to you if you want it to start as a system service. You’ll need to add two plists to /Library/LaunchDaemons (I’ll get to that in a moment), and you’ll also have to change some ownership of files. The first thing to do is:

$ sudo chown -R mysql:admin /Applications/MAMP/db/mysql
$ sudo chown -R mysql:admin /Applications/MAMP/tmp/mysql

The first is to grant ownership of the database files to user mysql (which is what the database will run as instead of, say, user joe (aka YOU)), and the second is to give user mysql write permissions to the temporary file directory where mysql wants to create it’s socket file (so as to communicate locally).

The plists you need are:

The second assumes you’ll be running mysql on the standard mysql port (and not the wierd non-standard port they use by default). Reboot and you’re good to go (make sure those plist files are owned root:admin).

That was one good thing… don’t even get my started on the new Zend Studio 5.5 beta that is “supposedly” a universal binary (hello… we need universal *libs* too people!)

25 Comments

  1. Matt Walsh

    You can get MAMP (the application) to start up on login. That doesnt bother me, personally.

    Nov 29, 2006 @ 14:30:58
  2. Vincent Danen

    Yeah, I’m well aware that you can start it at login; that wasn’t my issue. My issue was, and I quote:

    “The problem with MAMP, however, is that you have to run the stupid MAMP application to actually start the apache and mysql daemons; it doesn’t provide support to have them started on their own at system startup”

    So we’re talking about system startup, not user login, which are two entirely different things and MAMP does not, out of the box, support being started at boot, rather than when someone logs in.

    I want apache and mysql started before I even get to the login screen, nevermind my desktop.

    Nov 29, 2006 @ 20:52:08
  3. Mike

    Thank you so much for this. I always wanted to be able to start MAMP at system startup, but I never had the time to play around and figure it out.

    Today, for some unknown reason, my permissions went all screwy and MySQL wouldn’t start at all. I came across this blog and decided to make an attempt at changing the ownership and starting at boot – and everything worked without a hitch!

    Great article.

    Jan 11, 2007 @ 15:07:10
  4. Vincent Danen

    You’re welcome, Mike. Glad you found it useful.

    Jan 11, 2007 @ 15:27:01
  5. taber

    Gotta agree with Mike!! Thankfully Google pointed me your way… I hated quitting MAMP every time I logged in – this makes it wayyy less annoying! Thank you!!

    Jun 01, 2007 @ 23:18:33
  6. Vincent Danen

    You’re very welcome. MAMP is pretty slick, and with a few finesses it could be much nicer, but this does the trick anyways. Glad you found it useful.

    Jun 03, 2007 @ 09:57:27
  7. taber

    Thanks Vincent! FYI also in MAMP v1.6 (Pro only maybe?) they have a new checkbox in the General server prefs screen: “Start Apache and MySQL on system startup” so that works too!

    Jun 03, 2007 @ 15:06:16
  8. Vincent Danen

    Oh, there’s a new version out? I’ll have to check it out then. Hopefully that change isn’t Pro-only… that’s a pretty important thing to be able to do… =)

    Jun 09, 2007 @ 00:52:03
  9. wil

    Thank you for the great post, made my life a little easier. Now if only MAMP would integrate options to enable this on install… :)

    Jul 12, 2007 @ 01:51:30
  10. rich

    Thank you Vincent for this guide. It drove me crazy too to have to restart MAMP each time I reboot my Mac. Now it starts right up after reboot. How convenient. :)

    rich

    Nov 29, 2007 @ 08:52:34
  11. David

    The plist files is missing atm, and i’m having the exact same problems now.

    Any way they could get back online again? .. Would appreciate it very much so. :)

    Apr 06, 2008 @ 10:56:27
  12. victor

    the plists are not on the wiki the link points to, can you pls put the plists back on the wiki

    Jun 26, 2008 @ 01:12:11
  13. vdanen

    Sorry, those plists have moved… they’re now available here:

    http://linsec.ca/BitBucket

    I’ve also updated the links in the original article. Sorry about that.

    Jul 02, 2008 @ 17:11:06
  14. victor

    i’m curious about your instructions. i am not installing MAMP as a user, but as the admin of my computer. are these instructions only applicable if i install MAMP as a user? would you kindly tell me how to have MAMP login at system boot as admin? otherwise, following these instructions, letter for letter takes mysql server offline. thanks for your help and putting the plists back online…more help pls O_o? kthxbye

    Jul 05, 2008 @ 16:20:13
  15. vdanen

    The plists are back up, and have been since July 2 (3 days before you posted =).

    I have no idea if it is different for an admin vs a regular user. I installed these as an admin user, so I suspect there should be no difference. Also be aware I wrote this initially in Nov of 2006, so approx 1.5 years ago. MAMP may have changed stuff since then, I’m not sure. Sorry that’s not overly helpful, but you may want to take it up with the MAMP developers.

    Jul 11, 2008 @ 16:39:41
  16. yourboyvic

    would you be so kind as to show me how to autologin into mamp with lingon? (I figured asking was worth a shot)

    Sep 23, 2008 @ 07:19:29
  17. vdanen

    I’m not sure what you mean by “autologin into mamp”. Do you mean autostart mamp upon login? If you’ve looked at lingon, you’ll see it’s pretty straightforward. All you need to know is the path of the application to start and Lingon takes care of the rest. If you need to know the paths, look at the linked plists; they’ll tell you the paths for the MySQL and Apache binaries.

    Sep 23, 2008 @ 09:21:39
  18. yourboyvic

    thanks for your response… when I start MAMP, it asks for a password that I must manually enter. so this explains my ‘autologin into MAMP’ the effect desired is that I bypass the human entry of a password to start my apache and mysql servers in mamp. I’ve looked at lingon and I think this is my $25 dollar solution:

    http://labcoat.tauniverse.com/virtualinput/index.html

    what do you think?

    thanks for taking the time to respond to my questions

    -vic

    Sep 23, 2008 @ 19:21:43
  19. vdanen

    Well, I can’t tell you if that’s worth $25… it wouldn’t be to me, but it might be to you. =) I still don’t see why you’re not just starting apache and mysql from Lingon. You’re starting MAMP, but all MAMP does is start mysql and apache. So skip MAMP and start what *it* would start directly. You shouldn’t have to enter a password that way… I never have.

    Oct 01, 2008 @ 16:24:34
  20. Andrea

    I’ve tried to follow the instructions posted but….
    MySql wont work!

    Apache is OK but MySql does not start.
    In the log I’ve found this error

    090227 23:10:25 mysqld started
    090227 23:10:26 [Warning] You have forced lower_case_table_names to 0 through a command-line option, even though your file system ‘/Applications/MAMP/db/mysql/’ is case insensitive. This means that you can corrupt a MyISAM table by accessing it with different cases. You should consider changing lower_case_table_names to 1 or 2
    090227 23:10:52 InnoDB: Started; log sequence number 0 43655
    090227 23:10:52 [ERROR] Can’t start server : Bind on unix socket: Permission denied
    090227 23:10:52 [ERROR] Do you already have another mysqld server running on socket: /Applications/MAMP/tmp/mysql/mysql.sock ?
    090227 23:10:52 [ERROR] Aborting

    090227 23:10:52 InnoDB: Starting shutdown…
    090227 23:10:56 InnoDB: Shutdown completed; log sequence number 0 43655
    090227 23:10:56 [Note] /Applications/MAMP/Library/libexec/mysqld: Shutdown complete

    090227 23:10:56 mysqld ended

    What can I do? thank you!

    Feb 27, 2009 @ 15:17:02
  21. Simon

    Andrea,

    Had a similar problem. I found that if you run MAMP (GUI) after the above SUDO commands it stuffs things up and MySql doesn’t work. Running the SUDO comands again solves the problem–well it did for me.

    May 06, 2009 @ 05:19:07
  22. Matt Young

    Works very well except for one thing: after the chown, cannot restart MySQL using the MAMP widget and MAMP application. Must be some ownership/permission need changing.

    Aug 29, 2009 @ 15:07:06
  23. Matt Young

    It’s very nice now MySql and apache auto start on startup. However, I cannot restart apache using

    apachectl graceful
    httpd not running, trying to start
    (13)Permission denied: make_sock: could not bind to address [::]:80
    no listening sockets available, shutting down
    Unable to open logs

    apachectl stop
    httpd (pid 89?) not running

    Of course httpd is running and I can browse.

    It would be great if I can get this one bit working because sometime I change httpd.conf and would like to get apache restarted without reboot.

    Aug 29, 2009 @ 17:44:35
  24. Matt Young

    sudo apachectl graceful

    does it.

    Aug 29, 2009 @ 20:13:15
  25. Morris

    I follow the instructions and Apache works but MySql didn’t start and I don’t know why. It’s likely a permission issue but I couldn’t find a solution…so I made rollback :(

    Thanks anyway because this a cool idea :D

    Sep 10, 2009 @ 17:12:00

Leave a Reply

*