Profile pic of Tommy KuTommy Ku's Blog

Reading and thinking

An artisan command for using multiple environment configurations in Laravel 5

Posted on  by Tommy Ku

This post is more than 2 years old, it may contain outdated information

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...

This post first appeared on . Permalink:

About the author

Profile pic of Tommy Ku

Tommy Ku, a Hong Kong-based Software Engineer experienced developing PHP and Java-based web solutions and passionate in Web technology.

Also a hobbyist digital and film photographer.