|
5 | 5 | - [Environment Variable Types](#environment-variable-types)
|
6 | 6 | - [Retrieving Environment Configuration](#retrieving-environment-configuration)
|
7 | 7 | - [Determining The Current Environment](#determining-the-current-environment)
|
| 8 | + - [Encrypting Environment Files](#encrypting-environment-files) |
8 | 9 | - [Accessing Configuration Values](#accessing-configuration-values)
|
9 | 10 | - [Configuration Caching](#configuration-caching)
|
10 | 11 | - [Debug Mode](#debug-mode)
|
@@ -109,6 +110,70 @@ You may also pass arguments to the `environment` method to determine if the envi
|
109 | 110 | > **Note**
|
110 | 111 | > The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
|
111 | 112 |
|
| 113 | +<a name="encrypting-environment-files"></a> |
| 114 | +### Encrypting Environment Files |
| 115 | + |
| 116 | +Unencrypted environment files should never be stored in source control. However, Laravel allows you to encrypt your environment files so that they may be safely be added to source control with the rest of your application. |
| 117 | + |
| 118 | +<a name="encryption"></a> |
| 119 | +#### Encryption |
| 120 | + |
| 121 | +To encrypt an environment file, you may use the `env:encrypt` command: |
| 122 | + |
| 123 | +```shell |
| 124 | +php artisan env:encrypt |
| 125 | +``` |
| 126 | + |
| 127 | +Running the `env:encrypt` command will encrypt your `.env` file and place the encrypted contents in an `.env.encrypted` file. The decryption key is presented in the output of the command and should be stored in a secure password manager. If you would like to provide your own encryption key you may use the `--key` option when invoking the command: |
| 128 | + |
| 129 | +```shell |
| 130 | +php artisan env:encrypt --key=3UVsEgGVK36XN82KKeyLFMhvosbZN1aF |
| 131 | +``` |
| 132 | + |
| 133 | +> **Note** |
| 134 | +> The length of the key provided should match the key length required by the encryption cipher being used. By default, Laravel will use the `AES-256-CBC` cipher which requires a 32 character key. You are free to use any cipher supported by Laravel's [encrypter](/docs/{{version}}/encryption) by passing the `--cipher` option when invoking the command. |
| 135 | +
|
| 136 | +If your application has multiple environment files, such as `.env` and `.env.staging`, you may specify the environment file that should be encrypted by providing the environment name via the `--env` option: |
| 137 | + |
| 138 | +```shell |
| 139 | +php artisan env:encrypt --env=staging |
| 140 | +``` |
| 141 | + |
| 142 | +<a name="decryption"></a> |
| 143 | +#### Decryption |
| 144 | + |
| 145 | +To decrypt an environment file, you may use the `env:decrypt` command. This command requires a decryption key, which Laravel will retrieve from the `LARAVEL_ENV_ENCRYPTION_KEY` environment variable: |
| 146 | + |
| 147 | +```shell |
| 148 | +php artisan env:decrypt |
| 149 | +``` |
| 150 | + |
| 151 | +Or, the key may be provided directly to the command via the `--key` option: |
| 152 | + |
| 153 | +```shell |
| 154 | +php artisan env:decrypt --key=3UVsEgGVK36XN82KKeyLFMhvosbZN1aF |
| 155 | +``` |
| 156 | + |
| 157 | +When the `env:decrypt` command is invoked, Laravel will decrypt the contents of the `.env.encrypted` file and place the decrypted contents in the `.env` file. |
| 158 | + |
| 159 | +The `--cipher` option may be provided to the `env:decrypt` command in order to use a custom encryption cipher: |
| 160 | + |
| 161 | +```shell |
| 162 | +php artisan env:decrypt --key=qUWuNRdfuImXcKxZ --cipher=AES-128-CBC |
| 163 | +``` |
| 164 | + |
| 165 | +If your application has multiple environment files, such as `.env` and `.env.staging`, you may specify the environment file that should be decrypted by providing the environment name via the `--env` option: |
| 166 | + |
| 167 | +```shell |
| 168 | +php artisan env:decrypt --env=staging |
| 169 | +``` |
| 170 | + |
| 171 | +In order to overwrite an existing environment file, you may provide the `--force` option to the `env:decrypt` command: |
| 172 | + |
| 173 | +```shell |
| 174 | +php artisan env:decrypt --force |
| 175 | +``` |
| 176 | + |
112 | 177 | <a name="accessing-configuration-values"></a>
|
113 | 178 | ## Accessing Configuration Values
|
114 | 179 |
|
|
0 commit comments