What is the .env file for Laravel 5?

8
  • What is the .env file serving?

  • No app.php has env => env('APP_ENV','production') . What would this production be? What other string can go there?

  • And the var APP_ENV ? What does it mean?

  • asked by anonymous 04.10.2016 / 20:03

    2 answers

    12

    The .env file stores the Laravel environment settings.

    According to documentation :

    Environment Settings

    It is very useful to have different configuration values based on the environment in which the application is running. For example, you may want to use different cache drivers locally and another on the production server. This is very easy using the environment-based settings.

    To make this easy, Laravel uses the Vance Lucas PHP Library DotEnv (vlucas). In an initial installation of Laravel, the main directory of the application will contain the env.example. file. If you installed Laravel via Composer, this file will be automatically copied to .env . However, you can copy or rename it manually.

    All variables listed in this file will load the global super variable of PHP $_ENV when your application receives a request. You can use the utility utility function env to get these values. If you have reviewed the Laravel configuration files, you may have noticed that many of the options already use this utility function.

    You are free to modify your environment variables however you want, to your local application, or to your production server. However, your .env file should not be versioned, because each developer / server may need a different configuration of this file.

    If you are developing as a team, you can include the .env.example file and add some comments about the file configuration so that each developer clearly understands what settings they should make in their own .env to run their application .

    Accessing the Current Application Environment

    You can access the current environment of your application through the environmentdo facade App:

    $environment = App::environment();
    

    You can also pass arguments to the environment method to check if the current environment is what was passed by argument. You can even pass multiple environments or call the method multiple times if necessary:

    if (App::environment('local')) {
        // Aqui instruções para rodar no ambiente local
    }
    
    if (App::environment('local', 'staging')) {
        // Aqui instruções para rodar no ambiente local OU staging
    }
    

    An application instance can also be accessed by the app utility function:

    $environment = app()->environment();
    
        
    04.10.2016 / 21:15
    3
      

    What is the .env file for?

    The .env file is an easier way to load custom configuration variables that your application will need to have.

    This means that you will have to modify the file outside of the project, and all environment variables will always be defined no matter how you execute your code this is reflected even in PHP built-in servers.

      

    What would this production be?

    production is the environment your application is in, and can also be defined as local / p>

      

    And the var APP_ENV? What does it mean?

    ENV comes from Environment , which means Environment. Every created configuration generates a key with this value to define the environment in which your project is located.

    Details

    04.10.2016 / 21:13