Skip to content

Instantly share code, notes, and snippets.

@glideranderson
Created October 3, 2012 14:39
Show Gist options
  • Save glideranderson/3827263 to your computer and use it in GitHub Desktop.
Save glideranderson/3827263 to your computer and use it in GitHub Desktop.
Wordpress Config File for local, staging, and production servers (so you can keep in your version control)
/* This wordpress config allows for local, staging and production database definitions
* Wordpress is in a directory called 'wp', while wp-content is outside the 'wp'
*
* This also allows for a crazy directory structure:
* for example: my staging was http://mydomain.com/clients/sitename/
* but the server http_host variable will only recognize mydomain.com
* wordpress still needs to know where my site lives, thus the path variable
*/
/* Servers */
$config2hosts = array(
'production' => 'production.com',
'staging' => 'staging.com',
'local' => 'local.dev'
);
if( $_SERVER['HTTP_HOST'] == $config2hosts['local']) {
define( 'DB_NAME', 'local_name' );
define( 'DB_USER', 'local_user' );
define( 'DB_PASSWORD', 'local_pass' );
define( 'DB_HOST', 'local_host' );
$path = '';
} else if ($_SERVER['HTTP_HOST'] == $config2hosts['staging']) {
define( 'DB_NAME', 'staging_name' );
define( 'DB_USER', 'staging_user' );
define( 'DB_PASSWORD', 'staging_pass' );
define( 'DB_HOST', 'staging_host' );
$path = '/some/directory';
} else {
define( 'DB_NAME', 'production_db' );
define( 'DB_USER', 'production_user' );
define( 'DB_PASSWORD', 'production_password' );
define( 'DB_HOST', 'production_db_host' );
$path = '';
}
/* Telling Wordpress were to go */
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . $path . '/wp');
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME'] . $path);
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . $path . '/wp-content');
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . $path . '/wp-content');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment