laravel 错误:未指定应用程序加密密钥。但它存在

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

Error: No application encryption key has been specified. But it exist

phplaravel

提问by Esmatullah Arifi

I have a Laravel application which is working well, but whenever I view the log file there are hundreds of error

我有一个运行良好的 Laravel 应用程序,但是每当我查看日志文件时,都会出现数百个错误

production.ERROR: No application encryption key has been specified. {"exception":"[object] (RuntimeException(code: 0): No application encryption key has been specified.

production.ERROR: 未指定应用程序加密密钥。{"exception":"[object] (RuntimeException(code: 0): 未指定应用程序加密密钥。

exist in log file. There is a key in .envfile and also I tried php artisan key:generatecommand as well but the error still generated in log file without any visible error to users.

存在于日志文件中。中有一把钥匙。env文件,我也尝试过php artisan key:generate命令,但错误仍然在日志文件中生成,对用户没有任何可见的错误。

This error only appears in the production server's log file, not in my development pc.

此错误仅出现在生产服务器的日志文件中,而不出现在我的开发电脑中。

回答by Udhav Sarvaiya

php artisan key:generate 

This will generate a random key, you must restart the serverand you should no longer see the error message.

这将生成一个随机密钥,您必须重新启动服务器,您应该不会再看到错误消息。

run the following commands to clear the cache.

运行以下命令清除缓存。

php artisan config:clear
php artisan config:cache

回答by Bilal Khan

I'm face to the same issue I have searched a lot but in a YouTube video comment I have found a solution (I'm not sure this solution is good or not) but worked for me
copy APP_KEY from .env file
and past in app.php file (located in: your_project\config)
Your app.php will look like

我面临着同样的问题,我已经搜索了很多,但在 YouTube 视频评论中我找到了一个解决方案(我不确定这个解决方案是否好)但对我
有用从 .env 文件复制 APP_KEY
并过去app.php 文件(位于:your_project\config)
你的 app.php 看起来像

.
. 
.
‘key' => env(‘APP_KEY', ‘base64:insert key here'),
.
. 
.

回答by Amol Rokade

check the "key" variable form your config/app.php file, it should be

检查 config/app.php 文件中的“key”变量,它应该是

 'key' => env('APP_KEY'),

OR

或者

make like this

像这样

'key' => "Your key",

And Restart your php server.

并重新启动您的 php 服务器。

回答by Kapitan Teemo

try these commands:

试试这些命令:

composer install
php artisan key:generate
php artisan config:cache

回答by General Omosco

Add empty APP_KEY=inside .env without value if not exist, then delete config.phpinside bootstrap/cacherun php artisan key:generate

APP_KEY=如果不存在则config.php在没有值的 .env 中添加空,然后在bootstrap/cache运行中删除php artisan key:generate

回答by hardik prajapati

Yes the php artisan key:generatewill generate the key for you. like this in console

是的,php artisan key:generate它将为您生成密钥。像这样在控制台

$php artisan key:generate Application key [base64:soAqqNW/Kk85OclhmCKXj+u4nZGF142gEZHEY0Y1NXA=] set successfully.

$php artisan key:generate Application key [base64:soAqqNW/Kk85OclhmCKXj+u4nZGF142gEZHEY0Y1NXA=] set successfully.

you need to copy this key and put it into your .env file in APP_KEY=parameter.

您需要复制此密钥并将其放入您的 .env 文件中的APP_KEY=参数中。