问题描述
注意:此问题不是以下问题的重复:
Note: This question is not a duplicate of these questions:
- Laravel 5.2 not reading env file
- Laravel 5.2 .env sometimes doesn't load in time
我收到此错误:
production.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.' in /home/coder/.local/share/Trash/files/myblog/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:45
当我尝试dd($config['key']);
时,它返回'null'.甚至数据库环境变量也返回null.因此,这意味着Laravel无法从.env文件读取.
When I tried dd($config['key']);
it returns 'null'. Even the database environment variables return null. So it means that Laravel is not reading from the .env file.
- 原因是什么?
- 如何解决此问题?
现在,我已通过手动在Config/app.php文件中指定密钥并在Config/database.php文件中设置数据库值来解决此问题
我怀疑我对.env文件的权限/所有者错误.我正在使用基本操作系统
I suspect that I've got the permissions/owner wrong on the .env file. I'm developing in Elementary OS
推荐答案
要确保正在读取文件.env
的最新版本,请确保运行php artisan config:clear
.
To be sure that the latest version of you .env
file is being read make sure you run php artisan config:clear
.
您可能还需要运行php artisan key:generate
为您的应用生成密钥(如果尚未生成).同时检查密码是否为AES-256-CBC
或在config/app.php
中更好.
You may also want to run php artisan key:generate
to generate a key for your app (if you haven't already done so). It wouldn't hurt to check the your cipher is AES-256-CBC
or better in config/app.php
at the same time.
如果这是本地开发环境,并且您认为对.env
文件的权限可能是错误的,请像这样检查它们:
If this is a local dev environment and you think permissions to the .env
file might be wrong, check them like so:
# Check the permissions
cd /path/to/app
ls -l -a
# IF required change the file permissions
sudo chmod 660 .env
注意
另外请注意,根据您的开发环境,可以在homestead.yaml
或nginx.conf
之类的位置设置某些$_ENV
变量.
Note
Also be aware that depending on your development environment, some $_ENV
variables can be set in places like homestead.yaml
or nginx.conf
.
这篇关于Laravel 5.2未从Ubuntu上的.env读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!