Wordpress on Pantheon

By Alec Reynolds,
HTML code

Kalamuna doesn’t dabble in theology, so we tend not to participate in debates over CMS superiority. From our perspective, Wordpress and Drupal were created equal, solving similar problems in different ways for different people. It thus saddened us to think that Pantheon, our favorite hosting provider, might separate our client’s Drupal site from its Wordpress-powered blog. Fortunately, no such CMS sin was committed. Read on to grasp true content management nirvana!


Unite the People: Combine the Wordpress and Drupal Databases

Here is the first non-kosher part of the whole process. Because Pantheon doesn't allow you to create additional databases (believe me, I've tried), you'll need to combine your Wordpress database with your Drupal database. Most Wordpress installs are already prefixed with "wp"; if you're not using a table prefix, you'll need to add one. Make sure that you mark the prefix in your wp-config.php file. The default wp-config.php has a line that looks like this for setting the table prefix:

$table_prefix = 'wp_';


Now you should merge the databases together. I'm a terminal-oriented guy running Mac OS, so any Unix-like environment should be able to use these commands. To export the Wordpress table into wp-database.sql...

mysqldump -u username -ppassword wp_databasename > wp-database.sql



Now you can merge the Wordpress database into your Drupal database (note that these commands assume that you have the Wordpress and Drupal tables both loaded into your MySQL server).

mysql -u username -ppassword drupal_databasename < wp-database.sql



Finally, export the merged databases.

mysql -u username -ppassword drupal_databasename > merged-databases.sql



You'll upload this final merged-databases.sql to Pantheon


Set My Wordpress Free: Update wp-config.php To Use Pantheon Database Credentials

As I mentioned, Mike did the down-and-dirty work figuring out an appropriate way to gather Pantheon's database credentials and insert them into configuration files in his post on running CiviCRM in Pantheon. All we have to do is replace the old configuration variables in wp-config.php (the code that starts with "define('DB_NAME'), etc." and ends with "define('DB_HOST', etc.") with the following snippet:

define('WP_CACHE', true);

 * Pantheon Systems:
 * Repopulate needed variables based on the Pantheon environment if applicable.
//If we're on Pantheon...
  $env = json_decode($_SERVER['PRESSFLOW_SETTINGS'], TRUE);
  if (!empty($env['conf']['pantheon_binding'])) {
    $pantheon_db = $env['databases']['default']['default'];
    $pantheon_conf = $env['conf'];

    //Populate some helpful variables
    $db_name = $pantheon_db['database'];
    $db_user = $pantheon_db['username'];
    $db_password = $pantheon_db['password'];
    $db_host = 'dbserver.' . $pantheon_conf['pantheon_environment'] 
    . '.' . $pantheon_conf['pantheon_site_uuid'] . '.drush.in' 
    . ':' . $pantheon_db['port'];

    //Define Wordpress DB credentials
    define('DB_NAME', $db_name);

		/** MySQL database username */
		define('DB_USER', $db_user);

		/** MySQL database password */
		define('DB_PASSWORD', $db_password);

		/** MySQL hostname */
		define('DB_HOST', $db_host);

                $salt = md5($_SERVER['PRESSFLOW_SETTINGS']);
                //These settings set prefixes on your cookies so you
                //may login to the WP admin.
                define('USER_COOKIE', 'SESSuser' . $salt);
                define('PASS_COOKIE', 'SESSpass' . $salt);
                define('AUTH_COOKIE', 'SESSauth' . $salt);
                define('SECURE_AUTH_COOKIE', 'SESSsecure' . $salt);
                define('LOGGED_IN_COOKIE', 'SESSloggedin' . $salt);
                define('TEST_COOKIE', 'SESStest' . $salt);
	//These setting will be used on environments other than Pantheon (ie, your localhost)
	define('DB_NAME', 'local_db');

	/** MySQL database username */
	define('DB_USER', 'local_user');

	/** MySQL database password */
	define('DB_PASSWORD', 'local_password');

	/** MySQL hostname */
	define('DB_HOST', 'localhost');

After doing this, you'll want to define some variables for Wordpress so, in its sojourn through the migration wastes, it can find itself (and perhaps some mana):

/** Other constants that need to be dynamic for pantheon */
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/INSERT_WP_DIRECTORY');
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/INSERT_WP_DIRECTORY');

Let the Righteous Rejoice: Final Words

By this point, you should have a fully operational Wordpress installation. Big thanks to Matt Cheney (of Pantheon and Panopoly fame) for pointing us in the right direction and the priests at Pantheon for leading us non-believers into grace. Double kudos to Mike, the virtuous heathen, for independently pioneering everything in this post. Mike is also working on some cooler, more user-friendly Wordpress additions for Pantheon compatibility, so stay tuned for updates!

Alec Reynolds


When his long-standing interest in programming and this "internet thing" became relevant to his entrepreneurial inclinations, Alec found himself helping launch a series of startups. This experience has provided Alec with a deep understanding of young businesses and the product development process, where he participates from the code to the customer.