Skip to content

Instantly share code, notes, and snippets.

@wesrice
Created March 5, 2012 03:28
Show Gist options
  • Save wesrice/1976305 to your computer and use it in GitHub Desktop.
Save wesrice/1976305 to your computer and use it in GitHub Desktop.
WordPress Database settings for working in multiple environments
<?php
/* Replace database connection information in wp-config.php */
// Get the host
$host = $_SERVER['HTTP_HOST'];
if( $host === 'local.website.com' || $host === 'localhost:8888' ){
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', '');
// Define the Home URL (the url of the home page)
define('WP_HOME','http://local.website.com');
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://local.website.com');
} elseif( $host === 'dev.website.com' ){
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', '');
// Define the Home URL (the url of the home page)
define('WP_HOME','http://dev.website.com');
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://dev.website.com');
} elseif( $host === 'staging.website.com' ){
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', '');
// Define the Home URL (the url of the home page)
define('WP_HOME','http://staging.website.com');
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://staging.website.com');
} elseif( $host === 'www.website.com' || $host === 'website.com' ){
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', '');
// Define the Home URL (the url of the home page)
define('WP_HOME','http://website.com');
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://website.com');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment