Skip to content

Instantly share code, notes, and snippets.

@uhlhosting
Forked from MattWilcox/wp-config.php
Created March 28, 2018 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhlhosting/0663a5f8c34c1e0af55a7d991a3e8e50 to your computer and use it in GitHub Desktop.
Save uhlhosting/0663a5f8c34c1e0af55a7d991a3e8e50 to your computer and use it in GitHub Desktop.
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