Skip to main content

Laravel 5.4 .env files — how they autoload

Laravel 5.4 .env files — how they autoload

Laravel 5.4 .env files How do I load the .env.production file vs file or the base .env file?

In my vagrant box I had ...
        - 'APP_ENV dev'
After creating a , I noticed it was not loading that file!
Well, the bootstrap is auto detecting the app environment from the servers APP_ENV environment variable which can be set on the server or virtual host level of your server.
The code that does it... vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php
 * Detect if a custom environment file matching the APP_ENV exists.
 * @param  \Illuminate\Contracts\Foundation\Application  $app
 * @return void
protected function checkForSpecificEnvironmentFile($app)
    if (php_sapi_name() == 'cli' && with($input = new ArgvInput)->hasParameterOption('--env')) {
            $app, $app->environmentFile().'.'.$input->getParameterOption('--env')

    if (! env('APP_ENV')) {

    // this will load the .env.{APP_ENV} file
        $app, $app->environmentFile().'.'.env('APP_ENV')

Popular Posts