Skip to content

Instantly share code, notes, and snippets.

@charlie-s
Last active August 29, 2015 14:10
Show Gist options
  • Save charlie-s/edcf7d525c52ecd3bc9d to your computer and use it in GitHub Desktop.
Save charlie-s/edcf7d525c52ecd3bc9d to your computer and use it in GitHub Desktop.
OSX Dev Environment (Brew, Nginx, PHP, Mongo, Node, etc)

#Getting OSX Ready...#

Already have MySQL installed from a previous DMG or GUI installer? Follow the instructions at https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks to blast it away, backing up any data first.

Already have Apache running in OSX? You can turn it off since we'll be setting up Nginx below, or leave it running on port 80 – it won't affect what we're doing here.

Already have Homebrew installed? Run brew doctor and follow the free advice.

Ensure Xcode Command Line Tools are installed

xcode-select --install

Install Homebrew / Cask (if you don't already have them):

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap caskroom/cask
brew install brew-cask

Install apps via Homebrew / Cask:

brew tap homebrew/dupes
brew tap homebrew/php
brew install curl git node mysql freetype jpeg libpng gd zlib nginx dnsmasq mongodb imagemagick
brew install --without-apache --with-fpm --with-mysql php55
brew install mcrypt php55-mcrypt php55-yaml php55-imagick
brew cask install sequel-pro sourcetree launchrocket robomongo

Install NPM modules:

npm install -g nodemon grunt-cli bower serve

Configure PHP:

curl -fsSL https://gist.githubusercontent.com/csdco/676060f15ca91a5324f3/raw | sudo tee /usr/local/etc/php/5.5/php.ini > /dev/null
mkdir /var/www/_mailqueue
curl -fsSL https://gist.githubusercontent.com/csdco/a14e1df2d26a7f149bc2/raw | sudo tee /var/www/_mailqueue/_sendmail.php > /dev/null

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file: export PATH="$(brew --prefix homebrew/php/php55)/bin:$PATH"

Configure DNSMasq, ensure it will run at boot, and start it:

echo "address=/dev/127.0.0.1" | sudo tee /usr/local/etc/dnsmasq.conf > /dev/null
echo "listen-address=127.0.0.1" | sudo tee -a /usr/local/etc/dnsmasq.conf > /dev/null
sudo mkdir -p /etc/resolver
echo "nameserver 127.0.0.1" | sudo tee /etc/resolver/dev > /dev/null

Configure Nginx:

curl -fsSL https://gist.githubusercontent.com/csdco/4dc3689e62d855852661/raw | sudo tee /usr/local/etc/nginx/nginx.conf > /dev/null
sudo ln -s ~/Sites /var/www
sudo mkdir /var/log/nginx
mkdir ~/Sites/_nginx_vhosts
chgrp www-data /var/log/nginx
sudo nginx -s stop && sudo nginx

Configure MySQL / Sequel Pro

First, run mysql_secure_installation from terminal to tighten things up. By default, root has no password. You should set one, and should also follow the default Y/n options (choosing Y) to disallow remote login, remove test tables, etc.

To connect Sequel Pro to the MySQL server now running in OSX, use the following connection settings:

Type: Standard
MySQL Host: 127.0.0.1
Username: root
Password: (whatever password you gave root)
Database: (blank)
Port: 3306

LaunchRocket:

img

Open up System Preferences and select LaunchRocket. Click the "Scan Homebrew" button and configure which services you'd like to start now, at boot, etc. If any services aren't found as expected, you can load those services' plist files by hand from the following locations:

- PHP 5.5: /usr/local/opt/php55/*.plist
- MySQL: /usr/local/opt/mysql/*.plist
- Nginx: /usr/local/opt/nginx/*.plist
- DNSMasq: /usr/local/opt/dnsmasq/*.plist

#All done!##

Nginx/PHP Web Server

You can now browse ~/Sites by visiting http://localhost:8080/ in your browser.

Additionally, you can use the .dev top-level-domain with any subdomain that matches a sub-folder in ~/Sites. For example, visiting http://foo.dev:8080/ will deliver ~/Sites/foo/index.php.

You can also add any Nginx conf files into ~/Sites/_nginx_vhosts to setup your own virtual hosts. Here are a few examples:

- Drupal 7 in nested sub-dir, accessible at `example_d7.dev:8080`: https://gist.github.com/csdco/5f6b4934edfe63be4216

MySQL / MongoDB

You can launch Sequel Pro or Robomongo to browse MySQL and MongoDB databases, respectively.

Spin up vanilla servers whenever you want

You can use the npm module serve to spin up a vanilla server form any directory by typing serve.

NPM

Use NPM (http://npmjs.org/) to install Node.js modules to any project.

Grunt

Use Grunt (http://gruntjs.com/) to automate any tasks on a project, such as compiling SASS.

Bower

Use Bower (http://bower.io/) to install front-end dependencies to any project.

Nodemon

Use nodemon some-app.js to launch a Node.js server on a given script. The script will be monitored for changes and restarted automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment