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?
4
Answers
use these commands:
and make sure in
config/app.php
the key should be like:The
env()
helper searches the.env
file for a key=value pair by key.What you want to do is something like this:
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:
after modifying config file you might be required to do php artisan config:cache
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 onReveal Configs Vars
Go to your laravel local folder, open
.env
file and copyAPI_KEY
value. It will look like thisAPI_KEY=base64:HDDID98384JD8JD8498W
Copy the API KEY, navigate to back your heroku dasboard, on the
reveal configs var
section, typeAPI_KEY
in thekey
form field then paste your copied key value in thevalue
form field.Save and refresh your app. That should solve it!
Open command prompt in the root folder of your project and run below command:
It will generate Application Key for your application.
You can find the generated application key(APP_KEY) in .env file.