Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

@GustavoStraube Not a big deal, it was changed many times before sharing. I shared the old one only to demonstrate that I have the correct key. It is not a real key. Esmatullah Arifi Apr 9, 2021 at 17:40

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 have already told that I used this command but no change in the error log. I tried the last two commands as well.
– Esmatullah Arifi
                Oct 25, 2018 at 9:53
                @EsmatullahArifi please are you sure you have the key in .env file? remove .env.example file(if exists)
– Udhav Sarvaiya
                Oct 25, 2018 at 10:11
                Yes, I am sure 100%. this only happens in production server. In my own computer there is no error in log
– Esmatullah Arifi
                Oct 25, 2018 at 10:14
                Would you mind explaining what each of those commands do? I have had the same problem and even though I've been running config:clear, the error would still show. Now I ran also config:cache and I don't wanna jinx it but it looks like that did the trick.
– clesmalo
                Jun 25, 2020 at 17:02

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'),

make like this

'key' => "Your key",

And Restart your php server.

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.