Running MAMP Installed Services Without MAMP

Technical

Tonight, I walked in the door from work to this email from John:

Greetings. I read your post on running MAMP with virtual hosts, which was the same thing I did.

Now MAMP annoys me by prompting me for my credentials each time it launches, since 80 is a low port.

After reading your blog, I thought you'd be the kind of person whom that would annoy, too, and you would have already come up with a nifty startup thingy to get around it. I thought I would just request that you send it to me whilst I continue to bask here in my laziness.

Well, I hadn't come up with any such a "nifty startup thingy", but John's email amused me (by sounding remarkably similar to something I might say) so I thought I'd look into it.  I have MAMP in my login items so I got this same request for authorization every time I logged in, but I restart so seldom that I never really gave it much thought.  It was just part of my startup process.  My MAMP-related login flow goes like this: Login -> Authenticate to start the MAMP servers -> Quit MAMP (leaving the services themselves running).  Now that John mentioned it, that was annoying.  And now that it was on my mind, my annoyance would only grow.  Thanks for that, John.  :-)

So I started looking for a solution.  To solve the problem to my satisfaction, I needed to solve John's problem and then some.  Here's what I was after:

  1. I wanted to avoid the post-login credential validation.
  2. I wanted the services - Apache and MySQL - to start when I booted up.
  3. I did not want the MAMP application to start when I booted up (I mean, hell, the first thing I did was quit it).

Like any good Unix geek (or wannabe geek), I cracked open the terminal and found the first part of the solution.  Although stopping and starting Apache and MySQL from the command line are both fairly trivial tasks, MAMP ships with a handy shell script aptly named start.sh.  Guess what it does?  It calls startApache.sh and startMysql.sh.  Surprise.  I love when developers make it easy to work with their software.  After making sure that both servers were stopped, I executed the script:

$ sudo ./start.sh

Apache started fine, but MySQL wouldn't start.  Seems that since I installed MAMP as myself a few critical files were owned by me rather than by the system and that prevented sudo from doing what I needed with them.  To fix that, I modified the ownership of two directories:

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

Both statements grant ownership of the respective directories to the mysql user.  It should come as no great shock that this is the user that the MySQL server runs as rather than running as me or some other arbitrary user.  The first directory is the location of all of the database files and the second is a temporary file location to which MySQL needs to write from time to time.  Once these changes were made the start script ran as expected and both services started successfully.

The second part of that problem was to make the machine run that script at startup.  I guess I could have created an Automator application that executed the script and put the application in my login items, but that seemed too hacky for my tastes.  I like elegance.  Besides, that would only start the servers when I login.  I kind of wanted them to just start, you know, independent of me.  There may be other ways, but I chose to create a .plist file and save it in /Library/LaunchDaemons.  I created /Library/LaunchDaemons/info.mamp.servers.plist with the following content:





   Label
   info.mamp.servers
   ProgramArguments
  
       /Applications/MAMP/bin/start.sh
  

   RunAtLoad
  
   ServiceDescription
   This plist starts the Apache and MySQL servers that are shipped with MAMP

I rebooted and, with a kindly tip-o'-the-hat to Emeril, BAM!  I had services with no MAMP. 

I honestly don't know whether the secondary authentication when MAMP starts is caused by the low port number (80) that I use as John suggests or whether it has something to do with the permissions as they existed before I changed them or something else entirely.  All I know is that now that I'm not starting MAMP every time I login, I don't get the login box.  All three problems solved...even if I don't know exactly why one was a problem to begin with.

tags:
Mac, mamp
Chad said:
 
John's spot on. There is a cutoff port number below which services must run under root. That is why the default MAMP port after install is 8888.
 
posted 382 days ago
Add Comment Reply to: this comment OR this thread
 
 
I had no idea (obviously). Thanks. So, by starting services via launchd, am I effectively running them as root?
 
posted 382 days ago
Add Comment Reply to: this comment OR this thread
 
Jamie said:
 
Thanks for this brilliant solution. Very elegant, very useful.
 
posted 326 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Rob  Wilkerson