Environment

Each application is the combination of code and a set of configurations that dictates how that code should function. For example, you may have different database configurations locally than you have them on your production server.

The Quantum uses DotEnv and comes with .env.example file in the root directory which should be renamed to .env and where evnironment variables should be defined.


DB_DRIVER=mysql
DB_HOST=localhost
DB_NAME=
DB_USERNAME=
DB_PASSWORD=

        

To retrieve an environment variable, there is a helper function in the Quantum framework called env(). The second argument is the default value when no environment variable exists for the given key.


    env('DB_DRIVER', 'mysql');

        
Environment based configuration

Sometimes you might want to have different configuration files for different environments to execute the same codebase with different config parameters. For that typical reason there is a special config parameter app_env which can be defined in base config.php and can be named anything you like, but for convenience usually it can be named as development, staging, local, etc, by default it's production and reads the parameters from .env file.


return array(
    'app_env' => 'staging',
)

        

If the app_env value is set to statging, then the framework will look for environment variables in .env.staging file, similarly if app_env is equal to local then the environment variables will be fetched from .env.local file etc.

<< Prev Next >>