我正在尝试在一台服务器上设置我的暂存和生产区域。不用说,它不能用于登台 - 数据库连接错误。在当地工作!所以我使用了错误的主机名或其他东西。运行EC2。如何使用同一服务器区分登台和生产的主机名/服务器名称?
$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;
}