Reputation: 800
I am trying to load the local version of my database.php file located in my app/config/local directory. I have setup my $env environment detection in start.php for local.
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name')
));
The correct environment appears to be detecting correctly as the result of using:
App::environment('local')
evaluates as TRUE, however it only loads the default database.php in the app/config directory.
Just in case it was still related to detection I have tried just hardcoding local as the environment, but it has the same effect.
$env = $app->detectEnvironment(function()
{
return 'local';
});
I also tried using a different name for the environment in case 'local' had some undocumented reserved meaning.
I have successfully setup environments in other projects using Laravel 4, and I can't work out for the life of me what is different in this case. I'd appreciate any suggestions on what could lead to this behaviour.
The local environment is run on MAMP.
I just did an additional test and found that app.php file in my local folder loaded correctly. It is only the local database.php file that does not appear to be loading.
Upvotes: 2
Views: 1908
Reputation: 526
Production config files are loaded first and then merged with overrides from other environments. If the production file generates an error (e.g. undefined index) the config loading will bail early without loading the overrides. Check whether it's generating an error in the log. If so, in the production config file, check the value is set before attempting to use it and the local config file will then load correctly.
Upvotes: 2
Reputation: 146191
In your project inside app/config
directory you should create a directory named local
and then in that directory you should create a file named database.php
and in that fole you should provide the configuration, for example:
// File: app/config/local/database.php
return array(
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'myTestDb', // myTestDb is a db name for example
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
//...
),
),
);
Then in your project_folder/bootstrap/start.php
file use something like this:
$env = $app->detectEnvironment(array(
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net')
));
You may also check this answer for environment setup. This should work.
Upvotes: 1