1
I always see this command as a requirement to run cloned projects, but what is its purpose?
1
I always see this command as a requirement to run cloned projects, but what is its purpose?
6
The command key:generate
is used to set a new key in your file .env
, that is located in the home folder, it arrow the value within .env
in:
APP_KEY=<chave gerada>
Note that when running:
composer create-project --prefer-dist laravel/laravel <nome da pasta do projeto>
Or if you installed the installer (composer global require laravel/installer
):
laravel new <nome da pasta do projeto>
It will automatically execute the command without having to do it manually, it will only be necessary the command if you want a new key or if you have cloned a project that uses Laravel, but that is not the proper one.
The use of this key is as stated by the comments from the official code:
This key is used by the encryption service
Illuminate
and should be defined as a 32-character random string, otherwise these encrypted strings will not be secure. Do this before deploying an app!
That is, it is a key that is used in general for various functionalities that require encryption within Illuminate’s "Apis".
An important detail, as the colleague @Bacchus mentioned, the key should not be changed in a project that has already stored data based on this key (something done with the Illuminate Apis), if you do this will invalidate all data, which will break the application
If you are starting to use an Laravel-based project like October or any system the key should only be new if such a project has no database data or caches and is really starting from scratch.
Browser other questions tagged php laravel
You are not signed in. Login or sign up in order to post.
I think it’s worth mentioning that changing the key to a production environment can invalidate all data that used the previous key.
– Bacco
@Bacco because it is, taking out that the people at each new update of the Laravel think they should upgrade and Laravel 6 discovered a security flaw precisely in this key corrected, I think that in the end it should be all half broken even in this framework.
– Guilherme Nascimento
Precisely. I was in doubt whether to comment or not because of the fear of someone reading over and thinking that I use this kkk thing.
– Bacco