Drupal Development a la ThinkShout: setting up your environment

I’ve done more than my fair share of office IT support, and I feel pretty confident making existing software behave the way I want it to. Until, that is, it’s time to set up a development environment: the domain of developers is fraught with some particularly obtuse configuration oddities. To save headaches here at ThinkShout, I documented our basic setup steps, and thought it might be of use to the community. So, for anyone out there who just wants to get a Drupal development environment running with minimal headaches, I present “Drupal Dev a la ThinkShout in x Coherent Steps”. I’ll try to keep this updated based on feedback and changes over time. Let’s call this version 0.9 as of January 2013.

These instructions are designed for the following setup:

(Note: If you are in a hurry, you might want to start the large downloads before you begin the rest of the instructions. Xcode is the big one here.)

Step 0 – System settings

Apple Menu -> System Preferences -> Users & Groups
Make sure your account is an Administrator.

Apple Menu -> System Preferences -> Security & Privacy
Check the radio button for Anywhere under Allow Applications downloaded from.

Step 1 – Basic Tools

iTerm 2

First, get yourself a real Terminal program. We like iTerm 2.

Sublime 2

Now let’s get a nice text editor. For simple code edits and configuration file changes, we recommend sublime2 – it’s nag-ware, but it’s a very gental nag, and if you like it it’s only $59.
(Bonus! Launch Sublime from the command line: http://www.sublimetext.com/docs/2/osx_command_line.html )

Step 2 – Developer Tools


Much has been written about package managers, and to be honest I haven’t read much of it. But Homebrew works for me, and you’ll want to use it to make these instructions easy. To install Homebrew, pop on over to iTerm, paste in this command, and follow the prompts:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"


Now let’s head on over to Apple’s website and install Xcode. You’ll have to login with an Apple ID (free registration) to download, and it’s a doozy. Go make yourself a sandwich and crack a microbrew while you wait.
Once Xcode is downloaded, run the installer. When that completes, pop back into iTerm and paste in this command:
xcodebuild -license
(I’m not a lawyer, so I’ll let you make your own decision about agreeing to the license.. but if you don’t, the rest of these instructions might not work out)


No FOSS development environment is complete without git. You can DIY this part by going here, or you can just use Homebrow from iTerm:
brew install git brew update


While we’re at it, let’s install drush with Homebrew too:
brew install drush
That was easy!

Step 3 – Environment


Mac, Apache, MySQL, and PHP all in one package should make things easy, right? MAMP is great, but installing it is only the beginning: lots of little configuration options are hiding in the weeds. Some people like to use MAMP Pro, but I’m happy with basic MAMP. I’ve got the vital configuration options for you here, but you can read more details at D.O.

General MAMP


Drush Redux

Thought your Drush was all set? If only we were so lucky… Drush uses PHP, but if it points at a different PHP than MAMP is using, you’ll see some wacky errors on certain Drush operations. To avoid this, we put MAMP’s PHP at the beginning of our PATH variable:



Put mysql into your PATH by running this command in iTerm:
ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql
(Yes, there are other ways to do this, like adding /Applications/MAMP/Library/bin/ to your PATH – that’s fine if you prefer it and won’t interfere with the rest of our plans)

For many Drupal sites, you also need to increase your MySQL max_allowed_packet size: cp /Applications/MAMP/Library/support-files/my-small.cnf /Applications/MAMP/conf/ mv /Applications/MAMP/conf/my-small.cnf /Applications/MAMP/conf/my.cnf Now open /Applications/MAMP/conf/my.cnf in Sublime and search for max_allowed_packet. Set it to something like 64M and restart MySQL using MAMP.

Sequel Pro

Sequel Pro gives us a friendly interface to interact with MySQL. Download and install it.
Now run Sequel Pro. It’ll ask you for some settings. Use these:
name: local server: user: root pass: root port: 3306 (must match MAMP setup) And click Connect

Step 4 – Project Setup

Now that our environment is all shined-up, we need somewhere to put our work! You can put your Drupal root just about anywhere, but I like to create a file in my home directory called projects, so we’ll be using that as an example:
mkdir ~/projects
Our first project is a site that is going to bring about world peace, so let’s call it “worldpeace”: mkdir ~/projects/worldpeace
We need to tell Apache where to find our new website: let’s get the path: cd ~/projects/worldpeace pwd
Now open /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf in Sublime. There should be a nice example of how to add a virtual host in the file already, but go ahead and paste this code at the bottom:
<VirtualHost *:80> ServerAdmin email@address.com DocumentRoot "PATH/TO/projects/worldpeace/drupal" ServerName worldpeace.local ErrorLog "logs/worldpeace.local-error_log" CustomLog "logs/worldpeace.local-access_log" common </VirtualHost>

You’ll want to customize these lines to match your setup. Use the output from the “pwd” you just ran to get the DocumentRoot correct, and make sure to have unique names for each site’s log files. Now let’s tell our computer’s domain name service to look for this site on the local computer. Create a backup copy of /etc/hosts (cp /etc/hosts /etc/hosts.bak) before opening it in Sublime. Add a host line that looks like this: worldpeace.local The name must exactly match the “ServerName” we just set in httpd-vhosts.conf. Now go into MAMP and stop/start the Servers.

Let’s give our site a Database to work in, shall we?

All we need now is Drupal! You can go into your project folder and perform a git checkout if you are fancy, or setup a fresh installation. Since we installed Drush already, it’s pretty easy to setup a fresh site from iTerm (these instructions liberally cribbed from coderintherye.com). Note that these instructions assume that the most recent stable drupal is 7.18. If a newer version has been released, the “mv” command will need to be updated to match: cd ~/projects/worldpeace drush dl drupal mv drupal-7.18 drupal cd drupal drush site-install standard --db-url=mysql://root:root@localhost/worldpeace (That “–db-url” is formatted thusly: mysql://myslqusername:mysqlpassword@localhost/databasename)

Now point a web browser to http://worldpeace.local – so Drupalicious!

Get In Touch

Questions? Comments? We want to know! Drop us a line and let’s start talking.

Learn More
Get In Touch

Related Blog Posts