Created
September 16, 2019 08:35
-
-
Save michaeldeboeve/5a977af35e7436fdeb0e0edc660cc1d8 to your computer and use it in GitHub Desktop.
Wordpress multiple environments config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Default config settings | |
* | |
* Enter any WordPress config settings that are nonspecific to any environment | |
* in this file. | |
*/ | |
/** Database Charset to use in creating database tables. */ | |
define('DB_CHARSET', 'utf8'); | |
/** The Database Collate type. Don't change this if in doubt. */ | |
define('DB_COLLATE', ''); | |
/**#@+ | |
* Authentication Unique Keys and Salts. | |
* | |
* Change these to different unique phrases! | |
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} | |
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. | |
* | |
* @since 2.6.0 | |
*/ | |
define('AUTH_KEY', ''); | |
define('SECURE_AUTH_KEY', ''); | |
define('LOGGED_IN_KEY', ''); | |
define('NONCE_KEY', ''); | |
define('AUTH_SALT', ''); | |
define('SECURE_AUTH_SALT', ''); | |
define('LOGGED_IN_SALT', ''); | |
define('NONCE_SALT', ''); | |
/**#@-*/ | |
/** | |
* WordPress Localized Language, defaults to English. | |
* | |
* Change this to localize WordPress. A corresponding MO file for the chosen | |
* language must be installed to wp-content/languages. For example, install | |
* de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German | |
* language support. | |
*/ | |
define('WPLANG', 'nl_NL'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Setup environments | |
* | |
* Set environment based on the current server hostname, this is stored | |
* in the $hostname variable | |
* | |
* You can define the current environment via: | |
* define('WP_ENV', 'production'); | |
* | |
* @package Studio 24 WordPress Multi-Environment Config | |
* @version 1.0 | |
* @author Studio 24 Ltd <info@studio24.net> | |
*/ | |
// Set environment based on hostname | |
switch ($hostname) { | |
case 'localenvironment.local': | |
define('WP_ENV', 'local'); | |
break; | |
case 'stagingenvironment.com': | |
define('WP_ENV', 'staging'); | |
break; | |
default: | |
define('WP_ENV', 'production'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Development environment config settings | |
* | |
* Enter any WordPress config settings that are specific to this environment | |
* in this file. | |
* | |
* @package Studio 24 WordPress Multi-Environment Config | |
* @version 1.0 | |
* @author Studio 24 Ltd <info@studio24.net> | |
*/ | |
// ** MySQL settings - You can get this info from your web host ** // | |
/** The name of the database for WordPress */ | |
define('DB_NAME', 'name_database'); | |
/** MySQL database username */ | |
define('DB_USER', 'root'); | |
/** MySQL database password */ | |
define('DB_PASSWORD', 'root'); | |
/** MySQL hostname */ | |
define('DB_HOST', 'localhost'); | |
$table_prefix = 'wp_'; | |
/** | |
* For developers: WordPress debugging mode. | |
* | |
* Change this to true to enable the display of notices during development. | |
* It is strongly recommended that plugin and theme developers use WP_DEBUG | |
* in their development environments. | |
*/ | |
define('WP_DEBUG', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
*/ | |
/** | |
* WordPress Multi-Environment Config | |
* | |
* Loads config file based on current environment, environment can be set | |
* in either the environment variable 'WP_ENV' or can be set based on the | |
* server hostname. | |
* | |
* This also overrides the option_home and option_siteurl settings in the | |
* WordPress database to ensure site URLs are correct between environments. | |
* | |
* Common environment names are as follows, though you can use what you wish: | |
* | |
* production | |
* staging | |
* development | |
* | |
* For each environment a config file must exist named wp-config.{environment}.php | |
* with any settings specific to that environment. For example a development | |
* environment would use the config file: wp-config.development.php | |
* | |
* Default settings that are common to all environments can exist in wp-config.default.php | |
* | |
* @package Studio 24 WordPress Multi-Environment Config | |
* @version 1.0 | |
* @author Studio 24 Ltd <info@studio24.net> | |
*/ | |
define( 'WP_MAX_MEMORY_LIMIT', '1024M' ); | |
// Try environment variable 'WP_ENV' | |
if (getenv('WP_ENV') !== false) { | |
// Filter non-alphabetical characters for security | |
define('WP_ENV', preg_replace('/[^a-z]/', '', getenv('WP_ENV'))); | |
} | |
// Define site host | |
if (isset($_SERVER['X_FORWARDED_HOST']) && !empty($_SERVER['X_FORWARDED_HOST'])) { | |
$hostname = $_SERVER['X_FORWARDED_HOST']; | |
} else { | |
$hostname = $_SERVER['HTTP_HOST']; | |
} | |
// Try server hostname | |
if (!defined('WP_ENV')) { | |
// Set environment based on hostname | |
include 'wp-config.env.php'; | |
} | |
// Are we in SSL mode? | |
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { | |
$protocol = 'https://'; | |
} else { | |
$protocol = 'http://'; | |
} | |
// Load default config | |
include 'wp-config.default.php'; | |
// Load config file for current environment | |
include 'wp-config.' . WP_ENV . '.php'; | |
// Define WordPress Site URLs if not already set in config files | |
if (!defined('WP_SITEURL')) { | |
define('WP_SITEURL', $protocol . rtrim($hostname, '/')); | |
} | |
if (!defined('WP_HOME')) { | |
define('WP_HOME', $protocol . rtrim($hostname, '/')); | |
} | |
// define('UPLOADS', '_webdata'); | |
// Clean up | |
unset($hostname, $protocol); | |
/** End of WordPress Multi-Environment Config **/ | |
/* That's all, stop editing! Happy blogging. */ | |
/** Absolute path to the WordPress directory. */ | |
if ( !defined('ABSPATH') ) | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
/** Sets up WordPress vars and included files. */ | |
require_once(ABSPATH . 'wp-settings.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Production environment config settings | |
* | |
* Enter any WordPress config settings that are specific to this environment | |
* in this file. | |
* | |
* @package Studio 24 WordPress Multi-Environment Config | |
* @version 1.0 | |
* @author Studio 24 Ltd <info@studio24.net> | |
*/ | |
// ** MySQL settings - You can get this info from your web host ** // | |
/** The name of the database for WordPress */ | |
define('DB_NAME', 'name_database'); | |
/** MySQL database username */ | |
define('DB_USER', 'username_database'); | |
/** MySQL database password */ | |
define('DB_PASSWORD', 'password_database'); | |
/** MySQL hostname */ | |
define('DB_HOST', 'localhost'); | |
$table_prefix = 'wp_'; | |
/** | |
* For developers: WordPress debugging mode. | |
* | |
* Change this to true to enable the display of notices during development. | |
* It is strongly recommended that plugin and theme developers use WP_DEBUG | |
* in their development environments. | |
*/ | |
define('WP_DEBUG', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Staging environment config settings | |
* | |
* Enter any WordPress config settings that are specific to this environment | |
* in this file. | |
* | |
* @package Studio 24 WordPress Multi-Environment Config | |
* @version 1.0 | |
* @author Studio 24 Ltd <info@studio24.net> | |
*/ | |
// ** MySQL settings - You can get this info from your web host ** // | |
/** The name of the database for WordPress */ | |
define('DB_NAME', 'name_database'); | |
/** MySQL database username */ | |
define('DB_USER', 'username_database'); | |
/** MySQL database password */ | |
define('DB_PASSWORD', 'password_database'); | |
/** MySQL hostname */ | |
define('DB_HOST', 'localhost'); | |
/** | |
* For developers: WordPress debugging mode. | |
* | |
* Change this to true to enable the display of notices during development. | |
* It is strongly recommended that plugin and theme developers use WP_DEBUG | |
* in their development environments. | |
*/ | |
define('WP_DEBUG', false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment