Skip to content

Instantly share code, notes, and snippets.

@wesrice
Created September 19, 2012 15:35
Show Gist options
  • Save wesrice/3750307 to your computer and use it in GitHub Desktop.
Save wesrice/3750307 to your computer and use it in GitHub Desktop.
Multi-environment wp-config
// Get the host
$host = $_SERVER['HTTP_HOST'];
// Define the site base
$site_base = 'example.com';
// WP subdirectory
$wp_subdirectory = '';
if( $host === 'local.' . $site_base || $host === 'localhost:8888' ){
// Enable debugging
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Create a variable to identify what the environment is
define('WP_ENV', 'local');
// ** 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.' . $site_base);
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://local.' . $site_base . $wp_subdirectory);
} elseif( $host === 'dev.' . $site_base ){
// Enable debugging
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Create a variable to identify what the environment is
define('WP_ENV', 'dev');
// ** 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.' . $site_base);
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://dev.' . $site_base . $wp_subdirectory);
} elseif( $host === 'staging.' . $site_base ){
// Enable debugging
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Create a variable to identify what the environment is
define('WP_ENV', 'staging');
// ** 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.' . $site_base);
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://staging.' . $site_base . $wp_subdirectory);
} elseif( $host === $site_base || $host === 'www.' . $site_base ){
// Create a variable to identify what the environment is
define('WP_ENV', 'live');
// ** 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://www.' . $site_base);
// Define the Site URL (the url of the WordPress installation)
define('WP_SITEURL','http://www.' . $site_base . $wp_subdirectory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment