You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
17
17
18
+
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 and encryption key.
19
+
18
20
<aname="environment-configuration"></a>
19
21
## Environment Configuration
20
22
21
23
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.
22
24
23
-
To make this a cinch, Laravel utilizes the [DotEnv](https://github.com/vlucas/phpdotenv) 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 copied to `.env`. Otherwise, you should copy the file manually.
25
+
To make this a cinch, Laravel utilizes the [DotEnv](https://github.com/vlucas/phpdotenv) PHP library. In a fresh Laravel installation, the root directory of your application will contain a `.env.example` file that defines many common environment variables. During the Laravel installation process, this file will automatically be copied to `.env`.
24
26
25
-
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.
27
+
Laravel's default `.env` file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the `config` directory using Laravel's `env` function.
26
28
27
-
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.
29
+
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.
28
30
29
31
> {tip} Any variable in your `.env` file can be overridden by external environment variables such as server-level or system-level environment variables.
30
32
33
+
<aname="environment-file-security"></a>
34
+
#### Environment File Security
35
+
36
+
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.
37
+
31
38
<aname="environment-variable-types"></a>
32
39
### Environment Variable Types
33
40
34
-
All variables in your `.env` files are parsed as strings, so some reserved values have been created to allow you to return a wider range of types from the `env()` function:
41
+
All variables in your `.env` files are typically parsed as strings, so some reserved values have been created to allow you to return a wider range of types from the `env()` function:
35
42
36
43
`.env` Value | `env()` Value
37
44
------------- | -------------
@@ -44,27 +51,29 @@ empty | (string) ''
44
51
null | (null) null
45
52
(null) | (null) null
46
53
47
-
If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes.
54
+
If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes:
All of the variables listed in this file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` helper to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice several of the options already using this helper:
61
+
All of the variables listed in this file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` helper to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice many of the options are already using this helper:
55
62
56
63
'debug' => env('APP_DEBUG', false),
57
64
58
-
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.
65
+
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.
59
66
60
67
<aname="determining-the-current-environment"></a>
61
68
### Determining The Current Environment
62
69
63
70
The current application environment is determined via the `APP_ENV` variable from your `.env` file. You may access this value via the `environment` method on the `App`[facade](/docs/{{version}}/facades):
64
71
72
+
use Illuminate\Support\Facades\App;
73
+
65
74
$environment = App::environment();
66
75
67
-
You may also pass arguments to the `environment` method to check if the environment matches a given value. The method will return `true` if the environment matches any of the given values:
76
+
You may also pass arguments to the `environment` method to determine if the environment matches a given value. The method will return `true` if the environment matches any of the given values:
68
77
69
78
if (App::environment('local')) {
70
79
// The environment is local
@@ -74,35 +83,7 @@ You may also pass arguments to the `environment` method to check if the environm
74
83
// The environment is either local OR staging...
75
84
}
76
85
77
-
> {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.
When an exception is uncaught and the `APP_DEBUG` environment variable is `true`, the debug page will show all environment variables and their contents. In some cases you may want to obscure certain variables. You may do this by updating the `debug_hide` option in your `config/app.php` configuration file.
83
-
84
-
Some variables are available in both the environment variables and the server / request data. Therefore, you may need to hide them for both `$_ENV` and `$_SERVER`:
85
-
86
-
return [
87
-
88
-
// ...
89
-
90
-
'debug_hide' => [
91
-
'_ENV' => [
92
-
'APP_KEY',
93
-
'DB_PASSWORD',
94
-
],
95
-
96
-
'_SERVER' => [
97
-
'APP_KEY',
98
-
'DB_PASSWORD',
99
-
],
100
-
101
-
'_POST' => [
102
-
'password',
103
-
],
104
-
],
105
-
];
86
+
> {tip} The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
106
87
107
88
<aname="accessing-configuration-values"></a>
108
89
## Accessing Configuration Values
@@ -121,12 +102,19 @@ To set configuration values at runtime, pass an array to the `config` helper:
121
102
<aname="configuration-caching"></a>
122
103
## Configuration Caching
123
104
124
-
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.
105
+
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 can be quickly loaded by the framework.
125
106
126
-
You should typically run the `php artisan config:cache` command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
107
+
You should typically run the `php artisan config:cache` command as part of your production deployment process. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
127
108
128
109
> {note} If you execute the `config:cache` command during your deployment process, you should be sure that you are only calling the `env` function from within your configuration files. Once the configuration has been cached, the `.env` file will not be loaded and all calls to the `env` function will return `null`.
129
110
111
+
<aname="debug-mode"></a>
112
+
## Debug Mode
113
+
114
+
The `debug` option in your `config/app.php` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment variable, which is stored in your `.env` file.
115
+
116
+
For local development, you should set the `APP_DEBUG` environment variable to `true`. **In your production environment, this value should always be `false`. If the variable is set to `true` in production, you risk exposing sensitive configuration values to your application's end users.**
117
+
130
118
<aname="maintenance-mode"></a>
131
119
## Maintenance Mode
132
120
@@ -186,4 +174,4 @@ While your application is in maintenance mode, no [queued jobs](/docs/{{version}
186
174
<aname="alternatives-to-maintenance-mode"></a>
187
175
#### Alternatives To Maintenance Mode
188
176
189
-
Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like [Envoyer](https://envoyer.io) to accomplish zero-downtime deployment with Laravel.
177
+
Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like [Laravel Vapor](https://vapor.laravel.com) and [Envoyer](https://envoyer.io) to accomplish zero-downtime deployment with Laravel.
0 commit comments