Profile pic of Tommy KuTommy Ku's Blog

Reading and thinking

An artisan command for using multiple environment configurations in Laravel 5

Posted on March 27, 2015

The Laravel framework 5 has switched to DotEnv which does not support multiple environmental configuration. You get only one .env file for your Laravel app, only one. As @leonel pointed out in Setting up Laravel 5.0 for Openshift it seems like a pain unable to have multiple environmental settings.

So I wrote an artisan command for that

I have written an artisan command env:switch available at tommyku/laravel5_env, so you can switch between different .env files just by typing one line of command.

To save the current .env settings to .$APP_ENV.env, use --save option.

$ php artisan env
Current application environment: local
$ php artisan env:switch --save
Environmental config file .local.env saved

Edit .env for another set of environment configurations, test for example, save it again and feel free to switch to local.

$ php artisan env
Current application environment: test
$ php artisan env:switch --save
Environmental config file .test.env saved
$ php artisan env:switch local
Successfully switched from test to local.
$ php artisan env
Current application environment: local

Now you can include multiple *.env in your version control or share them with your teammates.

You could also look at...