Skip to content

Commit 6d0ba24

Browse files
[9.x] Adds documentation for env:encrypt and env:decrypt (laravel#8253)
* Add environment encryption * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8eb73d9 commit 6d0ba24

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

configuration.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Environment Variable Types](#environment-variable-types)
66
- [Retrieving Environment Configuration](#retrieving-environment-configuration)
77
- [Determining The Current Environment](#determining-the-current-environment)
8+
- [Encrypting Environment Files](#encrypting-environment-files)
89
- [Accessing Configuration Values](#accessing-configuration-values)
910
- [Configuration Caching](#configuration-caching)
1011
- [Debug Mode](#debug-mode)
@@ -109,6 +110,70 @@ You may also pass arguments to the `environment` method to determine if the envi
109110
> **Note**
110111
> The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
111112
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+
112177
<a name="accessing-configuration-values"></a>
113178
## Accessing Configuration Values
114179

0 commit comments

Comments
 (0)