Installing Homebrew, Nginx, MySQL, and PHP on Mac OS X

Thought I'd share a snippet on getting your Mac development environment set up.


# install homebrew
ruby -e "$(curl -fsSL"

# install homebrew's official php tap
brew tap josegonzalez/homebrew-php

# install homebrew's official nginx tap
brew tap homebrew/nginx

# install nginx + geoip + upload progress
brew install nginx-full --with-geoip --with-upload-progress-module

# install mysql
brew install mysql

# install php 5.5 + apcu + mcrypt + opcache + solr + xdebug
brew install --with-fpm --with-mysql php55  
brew install php55-apcu php55-mcrypt php55-solr php55-xdebug

# install composer globally
curl -sS | php  
mv composer.phar /usr/local/bin/composer

# set up mysql to run as user account
unset TMPDIR  
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

# launch mysql on startup
cp `brew --prefix mysql`/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/  
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# launch php-fpm on startup
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents  
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist 

# launch nginx at startup as root (in order to listen on privileged port 80):
sudo cp `brew --prefix nginx`/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/  
sudo sed -i -e 's/`whoami`/root/g' `brew --prefix nginx`/homebrew.mxcl.nginx.plist  
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

echo "  
1) configure intellij / netbeans / phpstorm / eclipse pdt to connect to xdebug on port 9009  

You can also download the gist here and execute the shell script in your terminal -

$ sh

Customize the script by adding or removing additional modules. For a list of nginx options, run the command (homebrew needs to be installed first) -

$ brew options nginx-full

I use PHPStorm as my go-to PHP IDE. Here's a link for instructions on how to setup your debugger -

Alex Ho

Alex is the Lead Developer at NYCEDC working as a front-end/back-end developer and sysadmin. He has a Graphic Design certification from NYU and is a UX practitioner.