我想为本地/ dev / production配置文件的单独副本,但不要让它们相互干扰,并且可能能够在版本控制中共存。
这个问题的优雅解决方案是什么?
答案 0 :(得分:2)
试试这个:
<?php
// rename this file to whatever your configuration file is supposed to be called (wp-config.php, etc.).
switch ($_SERVER['SERVER_NAME']):
// assuming your local server name is 'localhost,' leave this section alone
case 'localhost':
require_once('local.config.php');
break;
// replace production-url with the server name for your production site
case 'production-url':
require_once('production.config.php');
break;
// replace development-url with the server name for your development site
case 'development-url':
require_once('development.config.php');
break;
default:
// something went wrong;
endswitch;
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!