何时在Laravel中生成新的应用程序密钥? [英] When to generate a new Application Key in Laravel?

查看:58
本文介绍了何时在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是用于在.env文件中设置APP_KEY值的命令.默认情况下,此命令在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.

因此,只有在需要 调用php artisan key:generate时,TL:DR才遵循预先创建的Laravel项目的clone.

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的情况下运行Laravel项目(这是.env.example文件中的默认设置,则实际上会出现错误:

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中生成新的应用程序密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆