I’m trying to set up my staging and production areas on one server. Needless to say, it’s not working on staging – Database Connection error. Works on local! So I’m using the wrong host name or something. Running EC2. How do i differentiate the host names / server name for staging and production using the same server?
$environments = array(
'development' => 'radpress.dev',
'staging' => '**?????????????????????????**',
'production' => '**??????????????**',
);
// Get Server name
$server_name = $_SERVER['SERVER_NAME'];
foreach($environments AS $key => $env){
if(strstr($server_name, $env)){
define('ENVIRONMENT', $key);
break;
}
}
// If no environment is set default to production
if(!defined('ENVIRONMENT')) define('ENVIRONMENT', 'production');
// Define different DB connection details depending on environment
switch(ENVIRONMENT){
case 'development':
define('DB_NAME', 'radpress.dev');
define('DB_USER', 'lookrad');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('WP_SITEURL', 'THIS WORKS');
define('WP_HOME', 'THIS WORKS');
define('WP_DEBUG', true);
define('WP_CACHE', false );
break;
case 'staging':
define('DB_NAME', 'radpress.staging');
define('DB_USER', 'lookrad');
define('DB_PASSWORD', '');
define('DB_HOST', '??? IS THIS JUST THE HOSTNAME? ??');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', 'utf8_unicode_ci');
define('WP_SITEURL', 'IS THIS JUST THE PATH?? OR JUST THE SERVER NAME?' );
define('WP_HOME', 'IS THIS JUST THE PATH?? OR JUST THE SERVER NAME?' );
define('WP_DEBUG', TRUE );
define( 'WP_CACHE', TRUE );
break;
case 'production':
define('DB_NAME', 'radpress.production');
define('DB_USER', 'DBUSER');
define('DB_PASSWORD', 'PASSWORD');
define('DB_HOST', '127.0.0.1');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', 'utf8_unicode_ci');
define('WP_SITEURL', '');
define('WP_HOME', ');
define('WP_DEBUG', false);
define('WP_CACHE', TRUE );
break;
}