Forked from cballou/wordpress-multi-env-configphp-setup.php
Created
July 3, 2019 20:57
-
-
Save SherylHohman/9e9ea4df41cc0e8d47d505da305ffdfb to your computer and use it in GitHub Desktop.
Wordpress Multi-Environment wp-config.php Setup
This file contains hidden or 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 | |
/** | |
* This code is intended to be added to your wp-config.php file just below the top comment block. | |
* It should replace the existing define('DB_*') statements. You can add or remove sections | |
* depending on the number of environments you intend to setup. You should change all values of | |
* DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST for each environment, making them all distinct | |
* for security purposes. | |
*/ | |
// determine the current environment | |
define('APPLICATION_ENV', (getenv('ENVIRONMENT') ? getenv('ENVIRONMENT') : 'production')); | |
// set specific global database variables depending on your environment | |
if (APPLICATION_ENV != 'production') { | |
// turn on error reporting | |
error_reporting(E_ALL|E_STRICT); | |
ini_set('display_errors', 1); | |
// set your database credentials for each of your environments | |
if (APPLICATION_ENV == 'local') { | |
define('DB_NAME', 'myLocalDatabase'); | |
define('DB_USER', 'myLocalUser'); | |
define('DB_PASSWORD', 'myLocalPassword'); | |
define('DB_HOST', 'localhost'); | |
} else if (APPLICATION_ENV == 'dev') { | |
define('DB_NAME', 'myDevDatabase'); | |
define('DB_USER', 'myDevUser'); | |
define('DB_PASSWORD', 'myDevPassword'); | |
define('DB_HOST', '192.168.1.100'); | |
} else if (APPLICATION_ENV == 'staging') { | |
define('DB_NAME', 'myStagingDatabase'); | |
define('DB_USER', 'myStagingUser'); | |
define('DB_PASSWORD', 'myStagingPassword'); | |
define('DB_HOST', 'localhost'); | |
} | |
} else { | |
// turn off error reporting in production | |
error_reporting(0); | |
@ini_set(‘display_errors’, 0); | |
// set your production database values | |
define('DB_NAME', 'myProductionDatabase'); | |
define('DB_USER', 'myProductionUser'); | |
define('DB_PASSWORD', 'myProductionPassword'); | |
define('DB_HOST', 'localhost'); | |
} | |
// no need to touch these unless you have specific requirements to do so | |
define('DB_CHARSET', 'utf8'); | |
define('DB_COLLATE', ''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment