Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bits to add to wp-config.php to make things sane when developing in a real development system (local > stage > live) instead of developing directly on a live server. Which is what WP is set up to do and which is ridiculous.
/* Lets not rely on paths in the database, they can be very wrong when moving between dev/stage/live environments */
/* The following two variables are backward to my thinking, but hey, what ya gonna do? */
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . ''); // This is NOT the 'wordpress admin area' home, but the site's home
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/SECRETDIRECTORY'); // This isn't the site's URL but the WordPress admin area URL
/* MySQL settings */
switch($_SERVER['SERVER_NAME']){
// Your local machine's settings
case 'mysite.local':
define('DB_NAME', 'dev_mysite');
define('DB_USER', 'dev_mysite');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'mysql.local');
break;
// Your staging server's settings
case 'mysite.testing.com':
define('DB_NAME', 'stage_mysite');
define('DB_USER', 'stage_mysite');
define('DB_PASSWORD', 'otherpassword');
define('DB_HOST', 'localhost');
break;
// your live site's settings
default:
define('DB_NAME', 'mysite');
define('DB_USER', 'mysite');
define('DB_PASSWORD', 'livepassword');
define('DB_HOST', 'localhost');
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.