Skip to content

Instantly share code, notes, and snippets.

@iftee
Created June 1, 2016 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iftee/207de0a0c482cb82a72f84764864b57d to your computer and use it in GitHub Desktop.
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
<?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 );
?>
@vorticieflux6626
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment