# Configuration

  • Introduction

    All of the configuration files for the Laravel framework are stored in the **config**directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

    These configuration files allow you to configure things like your database connection information, your mail server information, as well as various other core configuration values such as your application timezone.

  • Application overview

    In a hurry? You can get a quick overview of your application's configuration, drivers, and environment via the about rails command:

    bin/rails about
    
    1
  • Environment Configuration

    It is often helpful to have different configuration values based on the environment where the application is running.

    To make this a easy, You can use DotEnv ( https://github.com/bkeepers/dotenv) . This enable you to load environment variable form .env file .

    Add this line to the top of your application's Gemfile:

    gem 'dotenv-rails'
    
    1

    and then execute

    bundle
    
    1

    To access any variable inside codebase , You just need to call

    ENV['vaiable_mane']
    
    1

    If you are developing with a team, you may wish to continue including a .env.example  file with your application. By putting placeholder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application.

    .

  • Environment File Security

    Your .env file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.

  • Retrieving Environment Configuration

    All of the variables listed in the .env file will be loaded into the Rails.application.config rails super-global when your application receives a request. However, you may use the ENV function to retrieve values from these variables in your configuration files. In fact, if you review the Rails configuration files, you will notice many of the options are already using this function:

    'api_only' => ENV('API_ONLY', false)

    The second value passed to the ENV function is the "default value". This value will be returned if no environment variable exists for the given key.