7

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.

Esmatullah Arifi
  • 812
  • 3
  • 12
  • 24

9 Answers9

8
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
Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
  • 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 '18 at 09:53
  • @EsmatullahArifi please are you sure you have the key in `.env` file? remove `.env.example` file(if exists) – Udhav Sarvaiya Oct 25 '18 at 10:11
  • 1
    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 '18 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 '20 at 17:02
  • If Laravel has cached a configuration value, updating the `.env` file won't have an immediate effect. You need to refresh the configuration cache using `php artisan config:cache` or clear the old cache with `php artisan config:clear` for the changes to take effect. – Shakil Alam Sep 01 '23 at 10:10
3

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.

hahamy
  • 81
  • 3
2

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’),
.
. 
.
Bilal Khan
  • 121
  • 4
1

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.

Amol Rokade
  • 145
  • 1
  • 11
1

try these commands:

composer install
php artisan key:generate
php artisan config:cache
Kapitan Teemo
  • 2,144
  • 1
  • 11
  • 25
1

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

Spinstaz
  • 287
  • 6
  • 12
0

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.

0

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

General Omosco
  • 606
  • 1
  • 10
  • 20
-1

All you need to do is

php artisan key:generate 

Reference

https://web-brackets.com/discussion/5/-solved-no-application-encryption-key-has-been-specified-

Mohamed Atef
  • 115
  • 8