php 未指定应用程序加密密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44839648/
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-08-26 03:02:42  来源:igfitidea点击:

No Application Encryption Key Has Been Specified

phplaravellaravel-5laravel-5.5artisan

提问by Carlos F

I'm new to Laravel and I'm trying to use the Artisan command...

我是 Laravel 的新手,我正在尝试使用 Artisan 命令......

php artisan serve

It displays...

它显示...

Laravel development server started: http://127.0.0.1:8000

Laravel 开发服务器启动:http: //127.0.0.1:8000

However, it won't automatically launch and when I manually enter http://127.0.0.1:8000it shows this error:

但是,它不会自动启动,当我手动输入http://127.0.0.1:8000时,它会显示以下错误:

RuntimeException No application encryption key has been specified.

RuntimeException 未指定应用程序加密密钥。

Any ideas? I'm using Laravel framework 5.5-dev.

有任何想法吗?我正在使用 Laravel 框架 5.5-dev。

回答by Amarnasan

From Encryption - Laravel - The PHP Framework For Web Artisans:

来自加密 - Laravel - Web Artisans 的 PHP 框架

"Before using Laravel's encrypter, you must set a key option in your config/app.php configuration file. You should use the php artisan key:generatecommand to generate this key"

“在使用 Laravel 的加密器之前,你必须在你的 config/app.php 配置文件中设置一个密钥选项。你应该使用 php artisan key:generate命令来生成这个密钥”

I found that using this complex internet query in google.com:

我发现在 google.com 中使用这个复杂的互联网查询:

"laravel add encrption key" (Yes, it worked even with the typo!)

“laravel 添加加密密钥”(是的,即使拼写错误也能正常工作!)

回答by Leonid Dashko

In my case, I also needed to reset the cached config files:

就我而言,我还需要重置缓存的配置文件:

php artisan key:generate
php artisan config:cache

回答by skm

Open command prompt in the root folder of your project and run below command:

在项目的根文件夹中打开命令提示符并运行以下命令:

php artisan key:generate

It will generate Application Key for your application.

它将为您的应用程序生成应用程序密钥。

You can find the generated application key(APP_KEY) in .envfile.

您可以在.env文件中找到生成的应用程序密钥(APP_KEY)。

回答by D J

Simply run this command:

只需运行此命令:

php artisan key:generate

回答by Adam Pery

  1. Copy .env.exampleto .env:

    cp -a .env.example .env

  2. Generate a key:

    php artisan key:generate

  3. Only then run:

    php artisan serve

  1. 复制.env.example.env

    cp -a .env.example .env

  2. 生成密钥:

    php artisan key:generate

  3. 然后才运行:

    php artisan serve

回答by Sabyasachi Ghosh

cp .env.example .envif there is no .env file present. php artisan key:generatecommand works for me. It generates the encryption key

cp .env.example .env如果没有 .env 文件存在。 php artisan key:generate命令对我有用。它生成加密密钥

回答by Craig Kollross

I actually had to add a .envfile to my project and then copy the contents of .env.exampleso that the key:generatewould work. Not sure why a .envfile was not created when I started the project.

我实际上不得不向我的项目添加一个.env文件,然后复制.env.example的内容,以便它key:generate可以工作。不知道为什么我开始项目时没有创建.env文件。

回答by José Maria

php artisan key:generate
php artisan config:cache

worked for me, but it had to be done in a command prompt on Windows.

对我有用,但必须在 Windows 上的命令提示符下完成。

Doing it inside the terminal in PHPStorm didn't worked.

在 PHPStorm 的终端内执行此操作无效。

回答by Udhav Sarvaiya

A common issue you might experience when working on a Laravel application is the exception:

在处理 Laravel 应用程序时,您可能会遇到的一个常见问题是:

RuntimeException No application encryption key has been specified.

RuntimeException 未指定应用程序加密密钥。

You'll often run into this when you pull down an existing Laravel application, where you copy the .env.examplefile to .envbut don't set a value for the APP_KEYvariable.

当您下拉现有的 Laravel 应用程序时,您经常会遇到这种情况,您将.env.example文件复制到该应用程序.env但不为APP_KEY变量设置值。

At the command line, issue the following Artisan command to generate a key:

在命令行中,发出以下 Artisan 命令以生成密钥:

php artisan key:generate

This will generate a random key for APP_KEY, After completion of .envedit please enter this command in your terminal for clear cache:php artisan config:cache

这将为 生成一个随机密钥APP_KEY,完成.env编辑后,请在您的终端中输入此命令以清除缓存:php artisan config:cache

Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart the serverchanging your .envfile values. now you will not get to see this error message.

此外,如果您使用 PHP 的默认 Web 服务器(例如php artisan serve),则需要重新启动服务器以更改.env文件值。现在您将看不到此错误消息。

回答by kaushik

Open command prompt in the root folder of your project and run

在项目的根文件夹中打开命令提示符并运行

php artisan key:generate

Then

然后

php artisan config:cache

and Then

进而

If you're getting the same error after having key-value, then just copy the APP_KEY value from .env file and paste it to config/app.php with 'key' => 'YOUR KEY',

如果您在获得键值后遇到相同的错误,那么只需从 .env 文件中复制 APP_KEY 值并将其粘贴到 config/app.php 并使用“key”=>“YOUR KEY”,

and then again run

然后再次运行

php artisan config:cache