Related
I'm trying to use the Artisan command like this:
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.
What's the cause of this problem, and how can it be fixed?
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"
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 it using this query in google.com:
"laravel add encrption key" (Yes, it worked even with the typo!)
Note that if the .env file contains the key but you are still getting an application key error, then run php artisan config:cache to clear and reset the config.
In my case, I also needed to reset the cached config files:
php artisan key:generate
php artisan config:cache
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.
Copy .env.example to .env:
cp -a .env.example .env
Generate a key:
php artisan key:generate
Only then run:
php artisan serve
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
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.
In 3 steps:
Generate new key php artisan key:generate
Clear the config php artisan config:clear
Update cache php artisan config:cache
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, 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.
Follow this steps:
php artisan key:generate
php artisan config:cache
php artisan serve
Simply run command php artisan key:generate.. Still issue exist then run one more command php artisan config:cache and php artisan cache:clear ..
Now run php artisan serve
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.
I found that most answers are incomplete here. In case anyone else is still looking for this:
Check if you have APP_KEY= in your .env, if not just add it without a value.
Run this command: php artisan key:generate. This will fill in the value to the APP_KEY in your .env file.
Finally, run php artisan config:cache in order to clear your config cache and recache your config with the new APP_KEY value.
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!
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.
If you don't have a .env file then run the below command, else skip this
cp .env.example .env
Then run the below artisan command and it will generate an application key for your project:
php artisan key:generate
Note: Your APP_KEY is inside your .env file.
If after running php artisan key:generate issue is not resolved, check your .env file.
Search for APP_KEY=.
If it doesn't exist, manually add it to .env file and run php artisan key:generate again.
After this you will see generated key in .env file.
Copy that key and paste it in /config/app.php (search for APP_KEY there as well). You should end up with something like this in app.php file
'key' => env('APP_KEY', 'base64:...'),
Then run php artisan serve (You might have to run php artisan config:cache at some point. Not 100% sure when)
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."
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.
Facing the Same Issue in Laravel v8.49.0 (PHP v8.0.6) Solution
Click
Genrate app key
Click on Refresh now
simply run
php artisan key:generate
its worked for me
Try setting correct file permissions
chmod -R 777 storage/
chmod 777 bootstrap/cache/
Run below command to set app key
php artisan key:generate
By running the above command, it sets the key value in .env of your project directory which is referenced in the app config
// .env
APP_KEY=base64:XkrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=
// config/app.php
'key' => env(APP_KEY);
Restart your server, in order to reflect the above change.
I had to restart my queue worker using php artisan queue:restart after running php artisan key:generate to get jobs working.
I have a problem with my project laravel 5.7. I have developed it locally and all is well but once sent to my server online I have this error: view [auth.login] not found.
Ran into the same problem. I noticed three things;
A message while booting homestead about virtualbox guest-tools being out of sync between host and guest. There could be a problem with paths. I fixed that issue with the help of this here
The Laravel view [auth.login] not found on server page displayed the path of the host machine and not of the vagrant-guest.
bootstrap/cache/config.php also displayed paths from the host and not the guest.
Renaming/deleting (or artisan cache:clear) the config.php only gave errors (Laravel Error “Unable to load the ”app“ configuration file”).
I fixed the issue by correcting the paths in config.php manually to the correct path in vagrant.
Run following commands on your server.
it might solve your problem.
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan route:cache
php artisan optimize
or
composer dump-autoload -o
if you are in develop mode you can run:
php artisan config:clear
or if you are in product mode you can run:
php artisan config:cache
notice: when you use second, config clear and cache again and you force to repeat command for other changes.
This frequently happens in my Laravel 5 app where sometimes .env variables cannot be read.
I have the following in my .env file:
STRIPE_SECRET=sk_test_mykey
STRIPE_KEY=pk_test_mykey
After clearing all the cache using all of these commands I still cannot access the STRIPE_SECRET variable:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
composer dump-autoload
I have tried in my controller using env('STRIPE_SECRET') and have also tried in tinker:
Any one know why this happens?
If you are running your server using php artisan serve.
You have to restart your server because built in server cache all the .env variables in its memory.
Just run this: php artisan config:clear
have you restarted your artisan server if not restart it and if you are using a virtual machine like vagrant try to get out of your machine and reload it using
vagrant reload
I'm trying to use the Artisan command like this:
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.
What's the cause of this problem, and how can it be fixed?
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"
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 it using this query in google.com:
"laravel add encrption key" (Yes, it worked even with the typo!)
Note that if the .env file contains the key but you are still getting an application key error, then run php artisan config:cache to clear and reset the config.
In my case, I also needed to reset the cached config files:
php artisan key:generate
php artisan config:cache
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.
Copy .env.example to .env:
cp -a .env.example .env
Generate a key:
php artisan key:generate
Only then run:
php artisan serve
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
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.
In 3 steps:
Generate new key php artisan key:generate
Clear the config php artisan config:clear
Update cache php artisan config:cache
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, 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.
Follow this steps:
php artisan key:generate
php artisan config:cache
php artisan serve
Simply run command php artisan key:generate.. Still issue exist then run one more command php artisan config:cache and php artisan cache:clear ..
Now run php artisan serve
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.
I found that most answers are incomplete here. In case anyone else is still looking for this:
Check if you have APP_KEY= in your .env, if not just add it without a value.
Run this command: php artisan key:generate. This will fill in the value to the APP_KEY in your .env file.
Finally, run php artisan config:cache in order to clear your config cache and recache your config with the new APP_KEY value.
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!
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.
If you don't have a .env file then run the below command, else skip this
cp .env.example .env
Then run the below artisan command and it will generate an application key for your project:
php artisan key:generate
Note: Your APP_KEY is inside your .env file.
If after running php artisan key:generate issue is not resolved, check your .env file.
Search for APP_KEY=.
If it doesn't exist, manually add it to .env file and run php artisan key:generate again.
After this you will see generated key in .env file.
Copy that key and paste it in /config/app.php (search for APP_KEY there as well). You should end up with something like this in app.php file
'key' => env('APP_KEY', 'base64:...'),
Then run php artisan serve (You might have to run php artisan config:cache at some point. Not 100% sure when)
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."
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.
Facing the Same Issue in Laravel v8.49.0 (PHP v8.0.6) Solution
Click
Genrate app key
Click on Refresh now
simply run
php artisan key:generate
its worked for me
Try setting correct file permissions
chmod -R 777 storage/
chmod 777 bootstrap/cache/
Run below command to set app key
php artisan key:generate
By running the above command, it sets the key value in .env of your project directory which is referenced in the app config
// .env
APP_KEY=base64:XkrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=
// config/app.php
'key' => env(APP_KEY);
Restart your server, in order to reflect the above change.
I had to restart my queue worker using php artisan queue:restart after running php artisan key:generate to get jobs working.
I launched sudo nohup php artisan queue:work --daemon on my server with laravel 5.1, and now I have change MAIL_HOST in my .env, (before I had "mail.mysitem.com" and now I put my intern ip example : 192.168.1.212 ) but it still send mail with old hostname, how I can apply change on .env?
I tried also with:
php artisan queue:restart
Give it a try with:
php artisan config:clear