Web Design

Pantheon in Local: A Safer Way

I've spoken before (several times actually) about Pantheon, a high performance web host.  They're an amazing platform with many awesome features, but one lacking feature is an easy way to do local development.  Kalabox 2 promises to change this, but as we went to press Pantheon integration wasn't working yet.  The good news: there's an easy way to do this.

For starters, Pantheon makes it very easy to pull down your content.  However, you're left with a problem: how to actually run your site locally.  If you're a beginner, you could use MAMP or Kalabox.  If you're a propeller head like me, you've already installed a full LAMP stack on Ubuntu.

But there's still a problem: you don't want to mess up settings.php.

When you're done working locally and want to push back up to Pantheon, the server will check sites/default/settings.php, and it will expect to see settings specific to Pantheon.  If you've edited that file for your local environment, you may have just broken your entire site.

The solution: multisite.  Kind of.

Multisite is a very fancy Drupal feature where you can host several different websites using the same code base.  Pantheon discourages this, but what we're doing here isn't really multisite.  It's a clever sleight of hand that protects settings.php but still lets you work locally - easily.

Let's Do It

Enough introduction.  Here's the magic.

  1. First, follow the instructions to pull down your site from Pantheon into your local environment.
  2. Open your site in your favorite file manager or IDE, and go inside the sites directory:
  3. Create a new folder called localhost:
  4. Set up this new directory just like you would for a new site (see instructions - especially the part about settings.php and the database):
  5. Use your favorite method to import the database to the local db you designated in settings.php.  I recommend drush.
  6. Go visit your local site, eg. http://localhost/code-demo .  And voila, your site is there!

Why does this work?  Because of the way Drupal resolves domain names.  Drupal will pick up "localhost" from the url and direct you to sites/localhost.

Why is this a good idea?  Because you never touch sites/default/settings.php .  It stays loaded with lots of Pantheon goodness.  Conversely, when you upload back to Pantheon, the server will ignore your sites/localhost.  Everybody wins.


There are lots of ways to pull a Pantheon site down to your local environment.  This way may not be the easiest, but it is the simplest.  I've had great success with this technique and I hope you will too.

clever girl