Using Homebrew to Support Drupal on OS X

Using Homebrew to Support Drupal on OS X

Ron Golan's picture

brew install command
Homebrew is a package manager that makes it easy to install UNIX tools which don't come with OS X. Using the Homebrew package manager provides a great amount of control over the software installed on an OS X system, and it can be used to provide missing elements to run Drupal directly on OS X as a development environment.

I didn't set out to use Homebrew. I simply wanted to use wget instead of curl. I had no idea that would lead me to completely change my development setup.

The wget command doesn't come with OS X. One can download the source and compile it or find a binary somewhere on the web, neither of which really sounded so appealing. So I decided to try an alternative: Homebrew. Homebrew is a package manager that makes it easy to install UNIX tools that don't come with OS X. Using to install wget was really simple. In fact, wget must be a popular package because Homebrew uses it as their first example on their homepage.

While I was at it, what else could I install? I removed the old Git binary I'd downloaded a year or two ago and never upgraded. Entering 'brew install git' installed the latest version. A simple 'brew install drush' and I had drush 5.0 installed. To upgrade those or any other brew installed packages all it takes is a 'brew update; brew upgrade'.

My development setup for a long time has been Linux on Virtualbox and I haven't been entirely satisfied with it. Everything on the Linux side is solid. No problems at all there. The issue has been with how I was running Linux on OS X. The virtualization definitely had some overhead and was using about 25% of my RAM. Virtualbox was also using single files as its filesystem, so backing it up was not efficient. I could see Virtualbox was consuming about 12-16% CPU even when the Linux OS was idle and I knew that was impacting my battery life.

Could Homebrew do what I needed to run my LAMP stack on OS X instead and just eliminate Virtualbox? MAMP does this by providing its own Apache, MySQL and PHP but OS X already has these except for MySQL. 'brew install mysql' fixed that. This time I actually used 'brew -v install mysql' so I could watch the progress. That was the easy part. The configuration changes to default OS X settings were a little more difficult. If you are not comfortable on the command line and haven't tweaked Apache before, you might want to use MAMP or some other packaged stack.

I tried to minimize changes to OS X defaults so to have a the least possible impact on the rest of the system and concentrate changes so that if anything breaks on upgrades, I know where to look. Performance and battery life is substantially better.

Drupal on OS X using Homebrew Recipe

Get homebrew . Follow the 'Install Homebrew Today!' link for the ruby command to run to get it installed. You will need to run that command as a user with Administrator privileges. As I said, I removed my old Git and reinstalled it with brew. If you don't have Git installed, start with that. You can skip wget if you want. Open Terminal and run these commands.

brew install git
brew install wget
brew install drush
brew -v install mysql

unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

mysql.server start
mysql.server stop

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.20/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Use sudo for admin privileges.

cd /var/mysql/
ln -s /tmp/mysql.sock

Apache config changes
In System Prefs, turn on Web Sharing to enable User web directories. ~/Sites will be used by default.

Use sudo for admin privileges.
Back up /etc/apache2/httpd.conf

chmod u+w httpd.conf

Edit httpd.conf as follows:

Uncomment the following lines.

#LoadModule php5_module        libexec/apache2/
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Add the following line after the Include line above.

Include /Users/<username>/Library/Vhosts/*.vhost

Replace with your username. Adding this Include line will give you a directory to use for vhost configuration files. I used the .vhost extension so I could remove vhosts by not using that extension.

apachectl graceful
chmod u-w httpd.conf

Create your ~/Library/Vhosts directory and add your vhost configuration files there. Using Apache virtualhosts is optional but the above recipe will allow it.


Very nice!

I actually like to use MAMP because of how simple it is to switch between PHP versions (oh legacy projects) but also makes creating vhosts ridiculously fast.

I might try this out though as it seems a more efficient way to get a standard LAMP setup working! Thanks! :)

You could also use Acquia DAMP stack (Dev Desktop):

Yesterday I installed Acquia Dev desktop in OSX, a very fast & easy install. Just needed to fix the link to drush and in under 10 minutes you have a full working Drupal development environment.

Also, you can use MNPP who come with all the "AMP" stack just replacing apache with Nginx and Mysql with Percona's version of Mysql.

Great recipe Ron! Thanks for sharing!

I piece meal a similar one adding homebrew-php and VirtualHostX which allowed me to add phpMyAdmin and set local VH with great ease.

Post new comment

About Urban Insight

We create elegant, mobile-friendly websites.

We solve complex problems using Drupal and open source software.

Learn More


To redirect all requests to HTTPS, place the following code into the vhost configuration file.

<IfModule mod_rewrite.c>
  RewriteEngine on
        RewriteCond %{SERVER_PORT} 80
        RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
        php_value session.cookie_secure 1