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
I'm getting this error:
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
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.
- What is the reason?
- How to fix this?
right now I've solved the issue by manually specifying key in Config/app.php file and setting the database values in Config/database.php file
I suspect that I've got the permissions/owner wrong on the .env file. I'm developing in Elementary OS
To be sure that the latest version of you .env
file is being read make sure you run php artisan config:clear
.
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.
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
Note
Also be aware that depending on your development environment, some $_ENV
variables can be set in places like homestead.yaml
or nginx.conf
.
I experienced this. And as a result of some hint given by @Spholt above, the reason was that apache(user www-data) could not read .env due to file permissions. So i changed the file permissions to ensure that the server (apache) had read permissions to the file. Just that and boom, it was all working now!