Autostart MySQL, PHP-FPM, and nginx on OS X Lion

In my last post, I wrote about my adventure setting up a local WordPress OS X nginx MySQL PHP web server on a Mac. You can use launchd to automatically start MySQL, PHP-FPM, and nginx on OS X. Create and install plist files in ~/Library/LaunchAgents to run programs at startup on a per-user basis or /System/Library/LaunchDaemons to start a daemon as root.

Use vi ~/Library/LaunchAgents/org.mysql.mysqld.plist to save a MySQL plist file:


Use vi ~/Library/LaunchAgents/org.php.php-fpm.plist to save a PHP-FPM plist file:


Use sudo vi /Library/LaunchDaemons/org.nginx.nginx.plist to save an nginx plist file:


Run the following commands to load the services for the first time:

launchctl load -w ~/Library/LaunchAgents/org.mysql.mysqld.plist
launchctl load -w ~/Library/LaunchAgents/org.php.php-fpm.plist
sudo launchctl load -w /Library/LaunchDaemons/org.nginx.nginx.plist

Run the following to check to see if the services are all running:

ps aux | grep mysql
ps aux | grep fpm
ps aux | grep nginx

Run the following to unload the services so they don’t keep autostarting again:

launchctl unload -w ~/Library/LaunchAgents/org.mysql.mysqld.plist
launchctl unload -w ~/Library/LaunchAgents/org.php.php-fpm.plist
sudo launchctl unload -w /Library/LaunchDaemons/org.nginx.nginx.plist

Run the following to stop the services:

msyql stop
sudo kill -SIGQUIT $( cat /usr/local/var/run/ )
sudo kill -QUIT $( cat /usr/local/nginx/logs/ )

Refer to man launchd.plist for more launchd parameters.