Configuration: Config
Configuration: Config
Introduction
Environment Configuration
Configuration Caching
Maintenance Mode
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.
Environment Configuration
It is often helpful to have different configuration values based on the
environment where the application is running. For example, you may
wish to use a different cache driver locally than you do on your
production server.
To make this a cinch, Laravel utilizes the DotEnv PHP library by Vance
Lucas. In a fresh Laravel installation, the root directory of your
application will contain a .env.example file. If you install Laravel via
Composer, this file will automatically be renamed to .env . Otherwise,
you should rename the file manually.
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.
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. You may also create a .env.testing file. This file
will override the .env file when running PHPUnit tests or executing
Artisan commands with the --env=testing option.
The second value passed to the env function is the "default value".
This value will be used if no environment variable exists for the given
key.
1 $environment = App::environment();
1 if (App::environment('local')) {
2 // The environment is local
3 }
4
5 if (App::environment(['local', 'staging'])) {
6 // The environment is either local OR staging...
7 }
{tip} The current application environment detection can be
overridden by a server-level APP_ENV environment variable. This
can be useful when you need to share the same application for
different environment configurations, so you can set up a given
host to match a given environment in your server's
configurations.
1 return [
2
3 // ...
4
5 'debug_blacklist' => [
6 '_ENV' => [
7 'APP_KEY',
8 'DB_PASSWORD',
9 ],
10
11 '_SERVER' => [
12 'APP_KEY',
13 'DB_PASSWORD',
14 ],
15
16 '_POST' => [
17 'password',
18 ],
19 ],
20 ];
1 $value = config('app.timezone');
Configuration Caching
To give your application a speed boost, you should cache all of your
configuration files into a single file using the config:cache Artisan
command. This will combine all of the configuration options for your
application into a single file which will be loaded quickly by the
framework.
You may also provide message and retry options to the down
command. The message value may be used to display or log a custom
message, while the retry value will be set as the Retry-After HTTP
header's value:
1 php artisan up