Created
June 1, 2016 12:52
-
-
Save iftee/207de0a0c482cb82a72f84764864b57d to your computer and use it in GitHub Desktop.
Conditional DB Secting in wp-config.php for maintaining WordPress from Development Server and Pushing to Production Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Unified variables | |
*/ | |
$charset = 'UTF-8'; | |
$collate = ''; | |
/* | |
* Set variables conditianlly based on current environment | |
*/ | |
if ( $_SERVER["HTTP_HOST"] === 'productionserver.com' ) { | |
$user_name = 'production_database_user_name'; | |
$hostname = 'production_database_host_name'; | |
$db_name = 'production_database_name'; | |
$password = 'production_database_password'; | |
} else if ( $_SERVER["HTTP_HOST"] === 'devserver.com' ) { // e.g. 'localhost' for local development | |
$user_name = 'dev_database_user_name'; | |
$hostname = 'dev_database_host_name'; | |
$db_name = 'dev_database_name'; | |
$password = 'dev_database_password'; | |
} | |
// ** MySQL settings - You can get this info from your web host ** // | |
/** The name of the database for WordPress */ | |
define( 'DB_NAME', $db_name ); | |
/** MySQL database username */ | |
define( 'DB_USER', $user_name ); | |
/** MySQL database password */ | |
define( 'DB_PASSWORD', $password ); | |
/** MySQL hostname */ | |
define( 'DB_HOST', $hostname ); | |
/** Database Charset to use in creating database tables. */ | |
define( 'DB_CHARSET', $chartset ); | |
/** The Database Collate type. Don't change this if in doubt. */ | |
define( 'DB_COLLATE', $collate ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! So this is how one might conditionally define the DB_HOST for WordPress? I have a local copy of several blogs, and a remotely hosted copy. Thanks!