何时在 Laravel 中生成新的应用程序密钥?
由于它会在我创建应用程序时自动在我的 .env
文件中为我设置,所以我不确定何时应该运行它.
Since it automatically sets it for me in my .env
file when I create the app, I'm not sure when I should run it.
除此之外,如果第二个开发人员进来并克隆应用程序,他/她是否需要运行 php artisan key:generate
?
In addition to that, if a second developer comes in, and clones the app, does he/she need to run php artisan key:generate
?
我们如何确切知道何时运行 php artisan key:generate
?
How do we know exactly when to run php artisan key:generate
?
推荐答案
php artisan key:generate
是一个在 中设置
文件.默认情况下,此命令在 APP_KEY
值的命令.envcomposer create-project laravel/laravel
命令之后运行.如果您使用像 git
这样的版本控制系统来管理您的项目以进行开发,调用 git push ...
会将您的 Laravel 项目的副本推送到它要去的任何地方,但不会包含您的 .env
文件.因此,如果有人使用 git clone ...
克隆您的项目,他们将不得不手动输入 php artisan key:generate
以使其应用正常运行.
php artisan key:generate
is a command that sets the APP_KEY
value in your .env
file. By default, this command is run following a composer create-project laravel/laravel
command. If you use a version control system like git
to manage your project for development, calling git push ...
will push a copy of your Laravel project to wherever it is going, but will not include your .env
file. Therefore, if someone clones your project using git clone ...
they will have to manually enter php artisan key:generate
for their app to function correctly.
所以,TL:DR 您需要调用 php artisan key:generate
的唯一时间是遵循预先创建的 clone
Laravel 项目.
So, TL:DR the only time you need to call php artisan key:generate
is following a clone
of a pre-created Laravel project.
旁注:如果您尝试运行一个 Laravel 项目并将您的 APP_KEY
设置为 SomeRandomString
(这是您的 .env.example
中的默认设置)code> 文件,你实际上会得到一个错误:
Side note: If you try to run a Laravel project with your APP_KEY
set to SomeRandomString
(which is the default in your .env.example
file, you will actually get an error:
未找到支持的加密器.密码和/或密钥长度无效.
No supported encrypter found. The cipher and / or key length are invalid.
相关文章