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.
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!)
In my case, I also needed to reset the cached config files:
php artisan key:generate
php artisan config:cache
Run the command php artisan key:generate
it will generate Application Key for your application. You can find the application key(APP_KEY) in .env
file.
simply run php artisan key:generate
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.
cp .env.example .env
if there is no .env file present.
php artisan key:generate
command works for me. It generates the encryption key
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.
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, you have to restart the server now you will not get to see this error message.
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.
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!