3

I have cloned a laravel project that I was working on from remote repository. After cloning it I ran all the usual commands like composer install, passport:install, key:generate and migrate. Now when I try to make a login request or browse to application url I get

"No Application Encryption key has been specified". 

I have generated keys multiple times and confirmed if the key exists in .env file or not. Even though everything seems to be in order I am still getting the error. I have also restarted the application server as well as the apache server with the hope that it will resolve but it didn't. I have no idea what to do now. Any suggestions?

Chilarai
  • 1,842
  • 2
  • 15
  • 33
samman adhikari
  • 571
  • 1
  • 7
  • 17
  • Does this answer your question? [No Application Encryption Key Has Been Specified](https://stackoverflow.com/questions/44839648/no-application-encryption-key-has-been-specified) – albus_severus Aug 21 '20 at 07:26
  • Are you using `php artisan serve` ? If yes, stop it and run it again. After every change in env file, you need to restart `php artisan serve`. – Suman B Aug 21 '20 at 08:07
  • @albus_severus No it doesn't. All the answers talk about key:generate and config:clear which I have already done. – samman adhikari Aug 21 '20 at 14:01
  • @SumanB I have restarted the server every time I generate a new key as mentioned in the question but I am still facing the problem. – samman adhikari Aug 21 '20 at 14:01
  • Are you working with Docker ? – melicerte Sep 29 '20 at 12:11
  • 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:13

4 Answers4

2

Open command prompt in the root folder of your project and run below command:

php artisan key:generate

It will generate Application Key for your application.

You can find the generated application key(APP_KEY) in .env file.

1

use these commands:

php artisan key:generate
php artisan config:cache

and make sure in config/app.php the key should be like:

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

The env() helper searches the .env file for a key=value pair by key.

What you want to do is something like this:

//in config/app.php
'key' => env(APP_KEY);

//in .env 
APP_KEY=base64:JjrFWC+TGnySLsldPXA*****Hpyjh8UuoPMt6yx2gJ8U=
mohammadreza khalifeh
  • 1,510
  • 2
  • 18
  • 32
1

Sometimes the application is not able to read the .env file and causes this issue. Regenerating Key will not help in those cases. You can try these solutions, I am sure one of them will surely help you.

Solution #1: chmod -744 .env

Solution #2: edit config.php & set your key directly in it, like this:

'key' => 'base64:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=',

after modifying config file you might be required to do php artisan config:cache

1

I believe that the answers so far provides solution for this question. But if you're deploying your laravel app on heroku, likely that if you use github deploy option on heroku, chances are there you will experience this kind of error reposnse when you deploy your app or when you open the deployed app url.

So if you get this errror via heroku RuntimeException No application encryption key has been specified

SOLUTION

On your heroku dashboard, navigate to settings Then click on Reveal Configs Vars Go to your laravel local folder, open .env file and copy API_KEY value. It will look like this API_KEY=base64:HDDID98384JD8JD8498W

Copy the API KEY, navigate to back your heroku dasboard, on the reveal configs var section, type API_KEY in the key form field then paste your copied key value in the value form field.

Save and refresh your app. That should solve it!

jovialcore
  • 601
  • 1
  • 5
  • 13