[php] No Application Encryption Key Has Been Specified

I'm new to Laravel and I'm trying to use the Artisan command...

php artisan serve

It displays...

Laravel development server started: http://127.0.0.1:8000

However, it won't automatically launch and when I manually enter http://127.0.0.1:8000 it shows this error:

RuntimeException No application encryption key has been specified.

Any ideas? I'm using Laravel framework 5.5-dev.

This question is related to php laravel laravel-5 laravel-5.5 laravel-artisan

The answer is


From Encryption - Laravel - The PHP Framework For Web Artisans:

"Before using Laravel's encrypter, you must set a key option in your config/app.php configuration file. You should use the php artisan key:generate command to generate this key"

I found that using this complex internet query in google.com:

"laravel add encrption key" (Yes, it worked even with the typo!)


A common issue you might experience when working on a Laravel application is the exception:

RuntimeException No application encryption key has been specified.

You'll often run into this when you pull down an existing Laravel application, where you copy the .env.example file to .env but don't set a value for the APP_KEY variable.

At the command line, issue the following Artisan command to generate a key:

php artisan key:generate

This will generate a random key for APP_KEY, After completion of .env edit please enter this command in your terminal for clear cache:php artisan config:cache

Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart the server changing your .env file values. now you will not get to see this error message.


You can generate Application Encryption Key using this command:

php artisan key:generate

Then, create a cache file for faster configuration loading using this command:

php artisan config:cache

Or, serve the application on the PHP development server using this command:

php artisan serve

That's it!


  1. Copy .env.example to .env:

    cp -a .env.example .env

  2. Generate a key:

    php artisan key:generate

  3. Only then run:

    php artisan serve


simply run

php artisan key:generate

its worked for me


Simply run this command:

php artisan key:generate

cp .env.example .env if there is no .env file present. php artisan key:generate command works for me. It generates the encryption key


Follow this steps:

  1. php artisan key:generate
  2. php artisan config:cache
  3. php artisan serve

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

php artisan key:generate

Then

php artisan config:cache

and Then

If you're getting the same error after having key-value, then just copy the APP_KEY value from .env file and paste it to config/app.php with 'key' => 'YOUR KEY',

and then again run

php artisan config:cache

I actually had to add a .env file to my project and then copy the contents of .env.example so that the key:generate would work. Not sure why a .env file was not created when I started the project.


Sometimes If everything Fails Use this:

Goto: laravelProject/config/app.php

Find the line: 'key' => and check to what it refers,

It can either be one of two:

Case 1: env('APP_KEY') Case 2: "somekeystring"

For Case 1: Goto your .env file after you have run cp -a .env.example .env Enter a random string like 10101010101010101010101010101010

Now, run php artisan key:generate

Your key will be updated automatically.

For Case 2: set a random string like for value of Key 10101010101010101010101010101010

Now, run php artisan key:generate

Your key will be updated automatically.


In 3 steps:

Generate new key php artisan key:generate

Clear the config php artisan config:clear

Update cache php artisan config:cache


Okay, I'll write another instruction, because didn't find the clear answer here. So if you faced such problems, follow this:

  1. Rename or copy/rename .env.example file in the root of your project to .env.

You should not just create empty .env file, but fill it with content of .env.example.

  1. In the terminal go to the project root directory(not public folder) and run

php artisan key:generate

  1. If everything is okay, the response in the terminal should look like this

Application key [base64:wbvPP9pBOwifnwu84BeKAVzmwM4TLvcVFowLcPAi6nA=] set successfully.

  1. Now just copy key itself and paste it in your .env file as the value to APP_KEY. Result line should look like this:

APP_KEY=base64:wbvPP9pBOwifnwu84BeKAVzmwM4TLvcVFowLcPAi6nA=

  1. In terminal run

php artisan config:cache

That's it.


I had to restart my queue worker using php artisan queue:restart after running php artisan key:generate to get jobs working.


I found that most answers are incomplete here. In case anyone else is still looking for this:

  1. Check if you have APP_KEY= in your .env, if not just add it without a value.
  2. Run this command: php artisan key:generate. This will fill in the value to the APP_KEY in your .env file.
  3. Finally, run php artisan config:cache in order to clear your config cache and recache your config with the new APP_KEY value.

In my case, while cloning the project from git there was no .env

file. So I copy the .env file from the source project and paste in my current project and change its configuration of database and it run successfully.


In my case, I also needed to reset the cached config files:

php artisan key:generate
php artisan config:cache

If you git clone some project then this kind of issue may usually occur.

  1. make sure there is .env file
  2. run php artisan key:generate and then it should generate APP_KEY in .env
  3. finally run php artisan serve and it should be working.

I ran into this issue when I manually copied the contents of my Laravel project (say sites/oldname) into a new directory on my Mac (say, sites/newname). Since I was manually dragging and droppping, it didn't grab the hidden files, namely, '.env'. When I looked more closely at sites/oldname I saw .editorconfig, .env, .env.example, .gitatrributes, .styleci.yml, etc.

The error went away once I copied the hidden files to the new directory.

So, "No Application Encryption Key Has Been Specified" is Laravel speak for "your .env file is missing."


php artisan key:generate
php artisan config:cache

worked for me, but it had to be done in a command prompt on Windows.

Doing it inside the terminal in PHPStorm didn't worked.


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.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-5

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Can't install laravel installer via composer Including a css file in a blade template? No Application Encryption Key Has Been Specified How to Install Font Awesome in Laravel Mix Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes Laravel 5.4 redirection to custom url after login How to set the default value of an attribute on a Laravel model laravel 5.3 new Auth::routes()

Examples related to laravel-5.5

"The page has expired due to inactivity" - Laravel 5.5 PHP Parse error: syntax error, unexpected '?' in helpers.php 233 No Application Encryption Key Has Been Specified

Examples related to laravel-artisan

No Application Encryption Key Has Been Specified Laravel 5.4 create model, controller and migration in single artisan command SQLSTATE[HY000] [2002] Connection refused within Laravel homestead ReflectionException: Class ClassName does not exist - Laravel Artisan, creating tables in database Laravel 5 Clear Views Cache Laravel 5 How to switch from Production mode Could not open input file: artisan Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist What are the Differences Between "php artisan dump-autoload" and "composer dump-autoload"?