Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jasonferrier
Last active October 10, 2015 03:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonferrier/3625513 to your computer and use it in GitHub Desktop.
Save jasonferrier/3625513 to your computer and use it in GitHub Desktop.
Wordpress auto-config for dev/test/live environments
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
* installation. You don't have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values.
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
preg_match("/^domain\.([a-z]+)\.whatev\.local/i", $_SERVER['HTTP_HOST'], $local_network);
switch ($_SERVER['HTTP_HOST'])
{
case 'domain.com.dev':
define('DB_NAME', 'dbname');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('WP_SITEURL', 'http://domain.com.dev/blog');
define('WP_HOME', 'http://domain.com.dev/blog');
define('WP_CONTENT_URL', 'http://domain.com.dev/blog/wp-content');
break;
case 'domain.' . $local_network[1] . '.whatev.local':
define('DB_NAME', 'dbname');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('WP_SITEURL', 'http://domain.' . $local_network[1] . '.whatev.local/blog');
define('WP_HOME', 'http://domain.' . $local_network[1] . '.whatev.local/blog');
define('WP_CONTENT_URL', 'http://domain.' . $local_network[1] . '.whatev.local/blog/wp-content');
break;
// This should default to the LIVE environment settings
default:
define('DB_NAME', 'dbname');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('WP_SITEURL', 'http://www.domain.com/blog');
define('WP_HOME', 'http://www.domain.com/blog');
define('WP_CONTENT_URL', 'http://www.domain.com/blog/wp-content');
break;
}
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content');
define('DISALLOW_FILE_MODS', TRUE);
define('WP_CACHE', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment