Handling multiple environments on the same machine with Laravel 4x
What if you wanted to run multiple environments on the same machine with the same name- for example, a staging and production AND local environment?
There is a better solution for handling environments in Laravel 4x- and it can be done by adding a one liner to you vhosts file- or .htaccess:
Set local environment variable
In vhost or .htaccess add for your local installation, for staging, for example add:
SetEnv LARAVEL_ENV staging
and the same in your production .htaccess or vhost:
SetEnv LARAVEL_ENV production
Then the usual detectEnvironment() function in start.php.
$env = $app->detectEnvironment(function()
{
// Default to local if LARAVEL_ENV is not set
return getenv('LARAVEL_ENV') ?: 'local';
});
We didn't forget local... and that's the the cool part-- your installation will default to local if neither environment variable is found in vhost or .htaccess, as they would be found in the other installations.