Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A database 'switch' in your wp-config.php
<?php
if ( stristr( $_SERVER['SERVER_NAME'], 'development' ) ) {
// ** MySQL settings DEVELOPMENT ** //
define( 'DB_NAME', 'projectname_dev' ); // The name of the database
define( 'DB_USER', 'projectname_dev_user' ); // Your MySQL username
define( 'DB_PASSWORD', '12345' ); // ...and a password an idiot would have on his luggage
define( 'DB_HOST', 'localhost' ); // 99% chance you won't need to change this value
define( 'WP_HOME', 'http://projectname.development.companyname.com' ); // home url
define( 'WP_SITEURL', WP_HOME ); // site url
define( 'WP_DEBUG', true ); // Debugging is always set to true on development!!!
define( 'WP_CACHE', false ); // You don't want caching while you are developing
} elseif ( stristr( $_SERVER['SERVER_NAME'], 'testing' ) ) {
// ** MySQL settings TESTING ** //
define( 'DB_NAME', 'projectname_tst' ); // The name of the database
define( 'DB_USER', 'projectname_tst_user' ); // Your MySQL username
define( 'DB_PASSWORD', '12345' ); // ...and a password an idiot would have on his luggage
define( 'DB_HOST', 'localhost' ); // 99% chance you won't need to change this value
define( 'WP_HOME', 'http://projectname.testing.companyname.com' ); // home url
define( 'WP_SITEURL', WP_HOME ); // site url
define( 'WP_DEBUG', true ); //Use the setting you want over here, could be true or false
define( 'WP_CACHE', false ); //Use the setting you want over here, could be true or false
} elseif ( stristr( $_SERVER['SERVER_NAME'], 'acceptance' ) ) {
// ** MySQL settings ACCEPTANCE ** //
define( 'DB_NAME', 'projectname_acc' ); // The name of the database
define( 'DB_USER', 'projectname_acc_user' ); // Your MySQL username
define( 'DB_PASSWORD', '12345' ); // ...and a password an idiot would have on his luggage
define( 'DB_HOST', 'localhost' ); // 99% chance you won't need to change this value
define( 'WP_HOME', 'http://projectname.acceptance.companyname.com' ); // home url
define( 'WP_SITEURL', WP_HOME ); // site url
define( 'WP_DEBUG', false ); //keep these settings identical to the production settings
define( 'WP_CACHE', true ); //keep these settings identical to the production settings
} else {
// ** MySQL settings PRODUCTION ** //
define( 'DB_NAME', 'projectname_prod' ); // The name of the database
define( 'DB_USER', 'projectname_prod_user' ); // Your MySQL username
define( 'DB_PASSWORD', '12345' ); // ...and a password an idiot would have on his luggage
define( 'DB_HOST', 'localhost' ); // 99% chance you won't need to change this value
define( 'WP_HOME', 'http://projectname.com' ); // home url
define( 'WP_SITEURL', WP_HOME ); // site url
define( 'WP_DEBUG', false ); //Debugging is always off on production sites
define( 'WP_CACHE', true ); //We want to cache our production site
}
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.