什么时候在 Laravel 中生成新的应用程序密钥?

When to generate a new Application Key in Laravel?(什么时候在 Laravel 中生成新的应用程序密钥?)
本文介绍了什么时候在 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 值的命令.env 文件.默认情况下,此命令在 composer 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 是跟随一个预先创建的cloneLaravel 项目.

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 设置为 SomeRandomString(这是您的 .env.example 中的默认值)的情况下运行 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.

这篇关于什么时候在 Laravel 中生成新的应用程序密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)