什么时候在 Laravel 中生成新的应用程序密钥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33370134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When to generate a new Application Key in Laravel?
提问by cyber8200
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.
由于它会.env
在我创建应用程序时自动在我的文件中为我设置它,因此我不确定何时应该运行它。
In addition to that, if a second developer comes in, and clonesthe 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
?
回答by Tim Lewis
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.
php artisan key:generate
是APP_KEY
在.env
文件中设置值的命令。默认情况下,此命令在命令之后运行composer create-project laravel/laravel
。如果你使用版本控制系统git
来管理你的开发项目,调用git push ...
会将你的 Laravel 项目的副本推送到它要去的任何地方,但不会包含你的.env
文件。因此,如果有人使用您的项目克隆了您的项目,git clone ...
他们将必须手动输入php artisan key:generate
才能使他们的应用程序正常运行。
So, TL:DR the only time you needto call php artisan key:generate
is following a clone
of a pre-created Laravel project.
因此,TL:DR 唯一需要调用的时间php artisan key:generate
是跟踪clone
一个预先创建的 Laravel 项目。
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:
旁注:如果您尝试运行 Laravel 项目并将您的APP_KEY
设置设为SomeRandomString
(这是您.env.example
文件中的默认设置),您实际上会收到错误消息:
No supported encrypter found. The cipher and / or key length are invalid.
未找到受支持的加密器。密码和/或密钥长度无效。
回答by Erich Meissner
The most important thing to do when cloning a laravel project is to first run composer update
then composer install
. The composer install
command installs any required dependencies for that laravel app.
克隆 laravel 项目时最重要的事情是首先运行composer update
then composer install
。该composer install
命令为该 Laravel 应用程序安装任何必需的依赖项。
The steps I took to clone a laravel project required the php artisan key:generate
command. I can see in my .env
file that there is an updated APP_KEY=base64:xxxxxxxxxxxxxxxxxxxx
after running this command.
我克隆 laravel 项目的步骤需要该php artisan key:generate
命令。我可以在我的.env
文件中看到APP_KEY=base64:xxxxxxxxxxxxxxxxxxxx
运行此命令后有更新。