Reputation: 1663
I've to deploy several instances of a Laravel app to a unique server. Each instance requires a different database configuration. The default Laravel's environment configuration based on hostnames doesn't work for me because all the apps are going to be on the same server, so there's no way to tell which config fiel to use. Here is my bootstrap/start.php
file:
$env = $app->detectEnvironment(array(
'development' => array('Ariels-MacBook-Pro.local'),
'server' => array('srv-hostname'),
));
It would be great that I can define the environment based upon a domain (because my apps area gonna be on diferent domains), so in this way I can define a different config for each domain (hosted on the same server)
Any ideas?
Upvotes: 2
Views: 2301
Reputation: 3375
My option, in file app/config/database.php
add this line at the end
'enviorement' => 'local',
// 'enviorement' => 'development', // this is for dev
// 'enviorement' => 'production', // this is for production
and then access from your controller with this
$env = Config::get('database.enviorement');
echo $env;
database.php
file is different, you have for ur local another for developemet server and another for producction because there is the "database conection" so i used it to implicit write the enviorement.
Have fun.
Upvotes: 0
Reputation: 166066
Laravel's detectEnvironment
method has a nify feature where you can progamatically determine the current enviornment with a closure. For example, this would configure Laravel to always use the local enviornment.
$env = $app->detectEnvironment(function()
{
return 'local';
});
The domain name should be somewhere in $_SERVER, so something like this untested pseudo-code should get you what you want.
$env = $app->detectEnvironment(function()
{
switch($_SERVER['HTTP_HOST'])
{
case: 'example.com':
return 'production';
case: 'another.example.xom':
return 'production';
default:
return 'local'; //default to local
}
});
Upvotes: 6