问题
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.
回答1:
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!)
回答2:
In my case, I also needed to reset the cached config files:
php artisan key:generate
php artisan config:cache
回答3:
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.
回答4:
Simply run this command:
php artisan key:generate
回答5:
Copy
.env.example
to.env
:cp -a .env.example .env
Generate a key:
php artisan key:generate
Only then run:
php artisan serve
回答6:
cp .env.example .env
if there is no .env file present.
php artisan key:generate
command works for me. It generates the encryption key
回答7:
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.
回答8:
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.
回答9:
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.
回答10:
Follow this steps:
php artisan key:generate
php artisan config:cache
php artisan serve
回答11:
Okay, I'll write another instruction, because didn't find the clear answer here. So if you faced such problems, follow this:
- 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.
- In the terminal go to the project root directory(not public folder) and run
php artisan key:generate
- If everything is okay, the response in the terminal should look like this
Application key [base64:wbvPP9pBOwifnwu84BeKAVzmwM4TLvcVFowLcPAi6nA=] set successfully.
- 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=
- In terminal run
php artisan config:cache
That's it.
回答12:
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!
回答13:
If you git clone some project then this kind of issue may usually occur.
- make sure there is
.env
file - run
php artisan key:generate
and then it should generate APP_KEY in .env - finally run
php artisan serve
and it should be working.
回答14:
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."
回答15:
I had to restart my queue worker using php artisan queue:restart
after running php artisan key:generate
to get jobs working.
回答16:
Open command prompt in the root folder of your project and run
php artisan key:generate
Than
php artisan config:cache
and Than
Till getting same error after having key value than just copy that APP_KEY value from .env file and paste it to config/app.php with 'key' => 'YOUR KEY',
and than again run
php artisan config:cache
来源:https://stackoverflow.com/questions/44839648/no-application-encryption-key-has-been-specified