問題描述
因為當(dāng)我創(chuàng)建應(yīng)用程序時它會自動在我的 .env
文件中為我設(shè)置它,所以我不確定我應(yīng)該什么時候運行它.
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.
除此之外,如果第二個開發(fā)人員進來并克隆應(yīng)用程序,他/她是否需要運行 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
是一個在你的 中設(shè)置
文件.默認(rèn)情況下,此命令在 APP_KEY
值的命令.envcomposer create-project laravel/laravel
命令之后運行.如果你使用像 git
這樣的版本控制系統(tǒng)來管理你的項目進行開發(fā),調(diào)用 git push ...
會將你的 Laravel 項目的副本推送到它要去的任何地方,但不會包含您的 .env
文件.因此,如果有人使用 git clone ...
克隆您的項目,他們將不得不手動輸入 php artisan key:generate
以使他們的應(yīng)用程序正常運行.
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 唯一一次您需要調(diào)用php artisan key:generate
是跟隨一個預(yù)先創(chuàng)建的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.
旁注:如果您嘗試在 APP_KEY
設(shè)置為 SomeRandomString
(這是您的 .env.example
中的默認(rèn)值)的情況下運行 Laravel 項目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.
這篇關(guān)于什么時候在 Laravel 中生成新的應(yīng)用程序密鑰?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!