Skip to content

Instantly share code, notes, and snippets.

@astockwell
Last active May 19, 2019 23:03
Show Gist options
  • Save astockwell/4320396 to your computer and use it in GitHub Desktop.
Save astockwell/4320396 to your computer and use it in GitHub Desktop.
One wp-config.php file to rule them all (multiple environments)
// One wp-config.php file for multiple environments setup from http://www.messaliberty.com/2010/01/how-to-create-a-single-wp-config-file-for-local-and-remote-wordpress-development/
if ($_SERVER['REMOTE_ADDR']=='127.0.0.1' || $_SERVER['REMOTE_ADDR']=='localhost' || preg_match('/^192\.168\.5\./', $_SERVER['REMOTE_ADDR'])) {
define('WP_ENV', 'local');
} elseif ($_SERVER['HTTP_HOST']=='tld.stagingurl.com') {
define('WP_ENV', 'staging');
} else {
define('WP_ENV', 'production');
}
if ( WP_ENV == 'local' ) {
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'replace_with_local_db'); // local_db_name
/** MySQL database username */
define('DB_USER', 'admin'); // local_db_user
/** MySQL database password */
define('DB_PASSWORD', 'admin'); // local_db_password
/** MySQL hostname */
define('DB_HOST', 'replace_with_local_ip'); // local_db_host
define('WP_SITEURL', ".dev");
define('WP_HOME', ".dev");
} elseif ( WP_ENV == 'staging') {
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'staging'); // staging_db_name
/** MySQL database username */
define('DB_USER', ''); // staging_db_user
/** MySQL database password */
define('DB_PASSWORD', ''); // staging_db_password
/** MySQL hostname */
define('DB_HOST', ''); // staging_db_host
define('WP_SITEURL', ".com");
define('WP_HOME', ".com");
} else {
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', ''); // prod_db_name
/** MySQL database username */
define('DB_USER', ''); // prod_db_user
/** MySQL database password */
define('DB_PASSWORD', ''); // prod_db_password
/** MySQL hostname */
define('DB_HOST', ''); // prod_db_host
define('WP_SITEURL', ".com");
define('WP_HOME', ".com");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment