什么时候在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:35:08  来源:igfitidea点击:

When to generate a new Application Key in Laravel?

phplaravellaravel-5consolelaravel-5.1

提问by cyber8200

Since it automatically sets it for me in my .envfile 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:generateis a command that sets the APP_KEYvalue in your .envfile. By default, this command is run following a composer create-project laravel/laravelcommand. If you use a version control system like gitto 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 .envfile. Therefore, if someone clones your project using git clone ...they will have to manually enter php artisan key:generatefor their app to function correctly.

php artisan key:generateAPP_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:generateis following a cloneof 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_KEYset to SomeRandomString(which is the default in your .env.examplefile, 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 updatethen composer install. The composer installcommand installs any required dependencies for that laravel app.

克隆 laravel 项目时最重要的事情是首先运行composer updatethen composer install。该composer install命令为该 Laravel 应用程序安装任何必需的依赖项。

The steps I took to clone a laravel project required the php artisan key:generatecommand. I can see in my .envfile that there is an updated APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxafter running this command.

我克隆 laravel 项目的步骤需要该php artisan key:generate命令。我可以在我的.env文件中看到APP_KEY=base64:xxxxxxxxxxxxxxxxxxxx运行此命令后有更新。