skip to Main Content

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


  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=
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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!

    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search