Laravel 5 utilizes the DotEnv PHP library, so environment configuration is now handled by the one single file: the
Configuring Environment Variables
If you created your Laravel 5 application using composer, you should, by default, already have a
.env file in your application’s main directory that looks something like this:
If you don’t already have a
.env file, just copy the
.env.example file and rename it to
This file contains all of your application’s environment variables.
By default, it’s set to use the
local environment, and, if created via Homestead, the default
The Laravel 5 Environment Configuration Keeps Your Credentials Secure
Note that since the
.env file contains sensitive information, it’s automatically added to the Laravel application’s
On the other hand, the
.env.example will be added to your Git repository. You should use the
.env.example to provide a template for your application’s standard configuration. That way, if anyone needs to work with your codebase, they’ll know which environment variables to define.
Configuring Multiple Environments With Laravel 5
Configuring multiple environments no longer requires managing multiple files. You simply:
- deploy your code to another environment; and
- create a new
.envfile with the appropriate environment variables.
Done! Easy as pie.