Drupal Dev on Mountain Lion

Setting up your Mountain Lion for Drupal development
Setting up your Mountain Lion for Drupal development

I am setting up a new laptop in front of The Wedding Singer, it's a good opportunity to record my current development environment on OSX. A few years ago it was all phpMyAdmin, PHPEclipse and MAMP. Drush was new and missing features. We needed CVS for Drupal development, and used SVN for our projects. It's nice to see how things change.

To put things in perspective, I am not a full-time developer, so I like to keep my environment as lean and native as possible. If I set up complexity, it is soon spoiled by entropy. I don't want to start a VM to develop Drupal. Where possible, I also like the configuration files in places they would be if I was managing a Linux server. 

Mountain Lion

Since Mountain Lion runs Apache 2.2 and PHP 5.3, I have long since said goodbye to MAMP and some of MAMP's assumptions and deeply hidden configuration files. My environment is a lot cleaner than past versions of OSX.

It's worth pointing out that running MAMP or Acquia Dev Desktop does not conflict with the software that OSX ships with. So don't be afraid to experiment on Mountain Lion. Just remember to watch the logs in /var/log for issues like trying to run multiple instances of Apache on port 80!

PHP and Apache

I can manage the configuration for PHP and Apache in /etc/php.ini and /etc/apache2. This is perfect for me. It's the first place I automatically look after months of not having to touch these files.

I am allergic to compiling code, so I get a little irritable when it comes to APC, XHProf, Memcache and other extensions. I download and compile these by hand into individual .so files, copy them into /usr/lib/php/extensions, and include them from the php.ini. In truth, it's all relatively painless with minimal dependencies.

Homebrew

I've had good experiences with Homebrew, and I like how it puts everything in /usr/local. It will be great when it is officially free of the dependency on XCode, which is a huge download just for a C compiler. I placate myself with the idea that I will one day experiment with iOS.

Note, for a while I was using Homebrew to compile a separate instance of PHP. Then using this as a dependency to install the extra PHP extensions I need. Having had some glitches doing this, I now find compiling these extensions manually is faster and simpler, and again leaves me with just one PHP executable.

Git is installed with Homebrew. And then I use Homebrew to install Drush and MariaDB (or MySQL if you prefer). Best of all, Homebrew gives me a speedy way to install random tools without having to switch into a sysadmin mindset, even though Homebrew is not as well integrated into OSX as Apt is into Debian.

CLI config

I use a basic set of tricks for the command line. I like a prompt that shows me the current Git branch, and has autocompletion for Git and Drush site aliases. Being deep inside Drupal directories can make the prompt long, so I also have a helper function to show a path relative to my sites directory.

 

#!/bin/bash
# Git CLI scripts.
source /usr/local/etc/bash_completion.d/git-completion.bash
source /usr/local/etc/bash_completion.d/git-prompt.sh
 
# Drush autocompletion for site aliases.
source /usr/local/Cellar/drush/5.9/libexec/drush.complete.sh
 
# Normal colours.
RED="\[\033[0;31m\]"   ; GREEN="\[\033[0;32m\]"  ; YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"  ; PURPLE="\[\033[0;35m\]" ; CYAN="\[\033[0;36m\]" 
WHITE="\[\033[0;37m\]"
 
# Bold colours.
BRED="\[\033[1;31m\]"   ; BGREEN="\[\033[1;32m\]"  ; BYELLOW="\[\033[1;33m\]"
BBLUE="\[\033[1;34m\]"  ; BPURPLE="\[\033[1;35m\]" ; BCYAN="\[\033[1;36m\]"
BWHITE="\[\033[1;37m\]"
 
# Set the prompt.
SITES_DIR="/Users/si/Technocrat/sites"
PS1="$BGREEN\$(relative_pwd "$SITES_DIR")$BPURPLE:$CYAN\$(__git_ps1 "%s")$BPURPLE$ $WHITE"
export PS1
 
# Readable colours for the ls command output on a dark background.
export CLICOLOR=1
export LSCOLORS=CxFxCxDxBxegedabagaced
 
# Executable paths, prefers homebrew paths.
export PATH="~/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:"
 
# Function to print the current path, potentially relative to the argument passed in.
# Helps shorten the prompt in deep directories.
relative_pwd()
{
  case $PWD in
    $1*) echo -n "/.."; echo $(pwd) | awk -F$1 '{print $2}' ;;
    *) echo $PWD ;;
  esac  
}
 

I don't have an extensive set of git aliases, but it's always odd to see when people don't use git aliases, so here is my ~/.gitconfig!

[alias]
  st = status
  ci = commit
  br = branch
  co = checkout
  df = diff
  lg = log -p
[user]
name = Si Hobbs
email = simon@hobbs.id.au
[color]
ui = true
[push]
default = simple

Other Tools

To wrap it up, I'll briefly describe the other tools I use:

  • Sublime Text 2 + the git extension
  • PHPStorm
  • Sequel Pro

 

The Author

James Harvey

Chief Development Officer