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

Viewed 13122

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

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

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

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

10 Answers
php artisan key:generate 

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

run the following commands to clear the cache.

php artisan config:clear
php artisan config:cache

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

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

I was stuck with this problem for a whole day and finally found out it was a permissions issue with the .env file. The file uploaded via scp has no read permissions.

chmod -744 .env

Hope this helps someone else with the same problem.

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

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

OR

make like this

'key' => "Your key",

And Restart your php server.

try these commands:

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

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

try to give permission if you're using ubuntu: *chmod -R 777 **

Check this link I hope it will help you.

I was able to get going by SSH access into the host that I installed the Laravel on, and then inside the public_html folder, I ran the command php80 artisan key:generate It generated the key, and then I refreshed the page, and continued with the install

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

$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.

Related