I am trying to setup environments in Drupal based on the URL. For example, if I go to mysite.local, it will use localdb and it will change the name of the site to "Local Mysite"; if I go to mysite.com, it will switch automatically to use productiondb and set the name to "Mysite".
This is a similar setup I use for most MVC based frameworks:
define('DEVELOPMENT', 'mysite.local');
define('PRODUCTION', 'mysite.com');
switch ($_SERVER['SERVER_NAME']) {
case DEVELOPMENT:
// development server
$config['base_url'] = "http://mysite.local";
$config['title'] = "DEVELOPMENT Mysite";
$config['debug'] = 1;
break;
default:
// live server
$config['base_url'] = "http://mysite.com/";
$config['title'] = "Mysite";
$config['debug'] = 0;
break;
}
Is there something like that in Drupal7 already (I don't want to use different sites, only different settings for the same site), and is there some sort of convention where this switch needs to happen (I am currently thinking about settings.php).
Personally I don't commit settings.php into version control, (settings.default.php is), then just keep a custom settings.php file based off settings.default.php in each environment.
However, if you prefer to setup your environments that way, then something like this would work in your sites/default/settings.php file.
define('DEVELOPMENT', 'mysite.local');
define('PRODUCTION', 'mysite.com');
switch ($_SERVER['SERVER_NAME']) {
case DEVELOPMENT:
// development server
$db_url = 'mysql://user:pass@localhost/mydb_dev';
$db_prefix = '';
$base_url = 'http://mysite.local';
$conf = array(
'site_name' => 'Development Environment',
);
break;
default:
// live server
$db_url = 'mysql://user:pass@localhost/mydb_prod';
$db_prefix = '';
$base_url = 'http://mysite.com';
$conf = array(
'site_name' => 'My Site',
);
break;
}
Remember, for each of these vars you use here, you need to comment out if they are defined in other parts of settings.php.
I should also add that I think multi-site for the purpose of a development environment is a bad idea, I guess for the same reason I prefer each environment having it's own custom settings.php file. In most cases, I prefer to keep the code portable in that I do not need any code or file system references to any environment except in a settings file for the environment I'm running the code on.
Using Drupal's multi-site functionality for every environment you need to develop and stage on, as others are suggesting here, would be insane to manage.