I thought the other day I should share how I setup my development environment on OS X. It’ll serve as a reminder for me too.

The first part is language-agnostic but the second part focuses on PHP.

Install Homebrew:

ruby -e "$(curl -fsSkL"

Install ZSH and Oh My Zsh:

brew install zsh zsh-completions
curl -L | sh

Configure ZSH mate ~/.zshrc:

Some notes here:

  • I changed the default theme to “af-magic” ( ZSH_THEME="af-magic" )
  • I’ve added the fpath command as told by the “zsh-completions” brew
  • Activated and added some alias
  • Added some plugins related to the tools I most often use
  • Important: I’ve changed the path so /usr/local/bin and /usr/local/sbin are upfront. Otherwise system binaries will be used instead of homebrew binaries (you get OS X’s php binary instead of the homebrew one).
# Path to your oh-my-zsh configuration.

# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.

# Completion
fpath=(/usr/local/share/zsh-completions $fpath)

# Example aliases
alias zshconfig="mate ~/.zshrc"
alias ohmyzsh="mate ~/.oh-my-zsh"
alias la="ls -la"

# Set to this to use case-sensitive completion

# Comment this out to disable weekly auto-update checks

# Uncomment following line if you want to disable colors in ls

# Uncomment following line if you want to disable autosetting terminal title.

# Uncomment following line if you want red dots to be displayed while waiting for completion

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git brew composer git-flow github node npm osx textmate)

source $ZSH/

# Customize to your needs...
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin

Install the github gem

Just use Homebrew: language-bash sudo gem install github

What about HTTP and database servers?

That’s right, how do I install Apache (or nginx)? How do I setup MySQL (or PostgreSQL)?

Well I don’t. I don’t like adding listening services on my Mac. It’s a security concern I don’t want to bother myself with. So either I use PHP’s 5.4 built-in web server + SQLite databases or I use a debian/ubuntu virtual machine, something I only run when I’m coding. The virtual machine setup also limit what you expose to the outer world. Your mails and other personal stuff are isolated. Another reason why I use a virtual machine is that my production servers will use Linux, not Mac OS and you should do development and continuous integration on the production system.

Install PHP

  • Tap the PHP repository formula
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
  • I suggest you take a look at the options before installing PHP:
brew options php54

I usually use --with-pgsql, --with-mysql, --with-suhosin, --with-fpm, --with-intl.

Now add the following path to your PATH (in the ~/.zshrc file): $(brew --prefix php54)/bin language-bash export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin becomes language-bash export PATH=$(brew --prefix php54)/bin:/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin This will make php binaries such as phpunit available.

Install PHPUnit

chmod -R ug+w `brew --prefix php54`/lib/php
pear config-set php_ini /usr/local/etc/php/5.4/php.ini
pear config-set auto_discover 1
pear update-channels
pear upgrade
pear install
brew unlink php54
brew link php54

The first command is to make it so you don’t have to use sudo when you install PEAR packages.

Install Composer

Just use Homebrew: language-bash brew install composer

Bonus: IntelliJ IDEA PHP project setup

A nice little tip if you’re an IntelliJ IDEA user: go to Preferences (cmd+,)/Project Settings/PHP/Include path and add (with the + button) the following path: /usr/local/opt/php54/lib/php/PHPUnit. Autocompletion for PHPUnit should now work. Do the same with any other system-wide PHP library you’d like to use.