Switching Wordpress Development / Live Environment (3.0 or higher)

For the Wordpress developers among us I thought I’d share the way I separate my development from the live environment.

I simply edited the wp-config.php file so that I check for the HTTP_HOST, specifically if it is the dev or the live URL. If it’s the live one I use the live database, no debugging and the live URL (no need to keep changing it in MySQL :) … if it’s the development one I use the dev db, debugging and dev url. All lines I added within the if statement I removed else where. I hope it helps! Code after the jump.

wp-config.php (for WP > 3.0)

/* Live */
$currenthost = $_SERVER['HTTP_HOST'];
if ($currenthost == 'LIVEURL.com' || $currenthost == 'www.LIVEURL.com') {
  define('DB_NAME', 'LIVE_DB_NAME');
  define('DB_USER', 'LIVE_DB_USER');
  define('DB_PASSWORD', 'LIVE_DB_PASSWORD');
  define('DB_HOST', 'LIVE_DB_HOST');
  define('DB_CHARSET', 'utf8');
  define('DB_COLLATE', '');
  define('WP_HOME','http://www.LIVEURL.com');
  define('WP_SITEURL','http://www.LIVEURL.com');
  define('WP_DEBUG', false);
} else {
  /* Development */
  define('DB_NAME', 'LOCAL_DB_NAME');
  define('DB_USER', 'LOCAL_DB_USER');
  define('DB_PASSWORD', 'LOCAL_DB_PASSWORD');
  define('DB_HOST', 'localhost');
  define('DB_CHARSET', 'utf8');
  define('DB_COLLATE', '');
  define('WP_HOME','http://localhost');
  define('WP_SITEURL','http://localhost');
  define('WP_DEBUG', true);
}