Reputation:
I would like to have seperate copies of configuration files for local/dev/production, but not have them interfere with each other and possibly be able to co-exist in version control.
What is an elegant solution to this problem?
Upvotes: 4
Views: 1667
Reputation:
Try this:
<?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!
Upvotes: 2