Related
On my production server I set the env var APP_ENV=production. With this config laravel will not use .env file but it will use env var declared on the server.
But I have a problem when I run this command php artisan key:generate because I'll get this error:
In KeyGenerateCommand.php line 96:
file_get_contents(/app/.env): failed to open stream: No such file or directory
Just for this command laravel need the .env file. So actually I create an empty .env file to make it works but it's ugly...
Do you have any solution ? or maybe this command is useless in production env ?
When you push a Laravel project to production, you need to generate a .env file, since that file is not committed. You should have a .env.example, which you can copy and modify as required:
cp .env.example .env
Then you can run php artisan key:generate to set the App Key.
You can also run this :
sudo php artisan key:generate
Before doing it make sure you are in the folder, for example :
cd /var/www/html/your_folder
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'm new to laravel and I want to learn it. I am trying to clone a github repository. The repository tells me I need to clone it, and then to run the 'composer install' command. But I get the following error:
[RuntimeException]
No supported encrypter found. The cipher and / or key length are invalid.
Script php artisan clear-compiled handling the post-install-cmd event returned with error code 1
I tried searching for this error on google and it told me to change the cipher to 'AES-256-CBC'. But when I checked the cipher it has the 'AES-256-CBC'.
Does anybody know how to resolve this problem?
you need .env file:
You can download env.example, rename it to .env and edit it. Just set up correct DB credentials etc.
Note: If you already have .env.example, just rename it to .env
Don't forget to When you use the php artisan key:generate it will generate the new key to your .env file
check your .env file,it has this APP-KEY filled!,if not there-then run this command.
php artisan key:generate
And after that check your .env file, there should be this type of line
APP_NAME=Laravel
APP_ENV=local
APP_KEY = ***keys_go_here***
....
and in your config/app.php,is there present this code of line.
'key' => env('APP_KEY')
After that do what you supposed to do previously.
You need to copy .env.example file and make new file in same directory name as .env
and then run
composer install
Try this in your console.first copy the .env.example
sudo cp .env.example .env
php artisan key:generate
if php artisan key:generate give permission error then giv permission to your .env
sudo chmod -R 777 .env
then
php artisan key:generate
first, install the Composer, then go to the project folder in cmd and run this command:
composer update
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 installed Laravel 5.0 properly by cloning in git, and composer install, when I ran it to browser http://localhost/laravel/public/, it says
"Whoops, looks like something went wrong."
I did not make any changes after composer install.
Update after copy the env.example to .env this is result
RuntimeException in compiled.php line 5599: OpenSSL extension is required.
The logs are located in storage directory. If you want laravel to display the error for you rather than the cryptic 'Whoops' message, copy the .env.example to .env and make sure APP_ENV=local is in there. It should then show you the detailed error messaging.
This is happening because there is a field in .env file named, APP_KEY, which is blank now, we need some random key for this variable.
Follow these steps to get rid of this problem.
Rename .env.example to .env
Go to your root directory in your command prompt (If you are using windows)/terminal (If you are using MAC or LINUX) where you have installed laravel project/files and run following command
php artisan key:generate
and then run your project.
It's all done.
Give write permission to storage and bootstrap/cache directories
Rename .env.example file to .env
If you get "RuntimeException... No supported encrypter found. The cipher and / or key length are invalid." error, stop the application and generate key from command line "php artisan key:generate"
If your get "OpenSSL extension is required" error, enable the openssl extension by opening php.ini in php installation folder and uncommenting the line extension=php_openssl.dll by removing the semicolon at the beginning
Follow these steps to this problem for all versions of your laravel like laravel 5.5
Step: 1
Rename file .env.example to .env
Step: 2
Go to your Command prompt/terminal and change path to project directory.
Generate key for your application. This is unique for every application so don't make copy paste.
Just run the following command. Key will automatically save to your .env file
php artisan key:generate
Try to type in cmd:
php artisan key:generate
the problems will be solved
Please, try to find something like:
./website/config/app.php and set 'debug' => env('APP_DEBUG', false) as 'true' 'debug' => env('APP_DEBUG', true)
Simply type in terminal in your command prompt go to laravel directory path and type php artisan key:generate then key will be generated. Paste that key in config/app.php key variable. Your problem will be solved. I also did like that inorder to solve the problem...
Try this:
sudo chown -R www-data pathto/.env
BECAUSE IF After Creating the .env file or/and Generating the Key by
php artisan key:generate
just as explained previously by others, and it still persists
Try the following:
ls path/.env -al
if apache doesn't have access to it by displaying
www-data
as one one of the users i mean like
-rw-rwx--- 1 www-data rootuser 575 Nov 4 06:34 pathto/.env
This as stated above should resolve it. Especially when your laravel.log file keeps complaining that the key hasn't been generated or added.
sudo chown -R www-data pathto/.env
In Laravel 5.5, I had the same issue
.env
was added to .gitignore.
So Either remove ".env" it from .gitignore file.
or add it forcefully
git add .env -f
And Deploy it. It will work.
If above does not help. Try generating the Key Again
php artisan key:generate
Check, which PHP version is running on your WAMP,XAMPP or LARAGAN server. It should be greater than 7.0.
Go to project folder like "C:\wamp\www\laravel".
Open the file name of .env.example. (By using any editor like sublime, notepad++ and so on).
Save as a .env
Then run your LARAVEL program. Hope it will work.
You can check whether how to change the PHP version in your current server. xampp, wamp
I renamed the .env.example to .env and ensure
APP_ENV=local
which showed me the actual error. It was related to key.
Then I issued
php artisan key:generate
command and it worked
For windows users, make sure apache's ssl_module is checked.
Please see image below:
First run command composer install
Then check for .env.example and .env files in your project folder.
.env file is your main configuration file for database and .env.example is backup file for .env file.
.env.example file will always be there but sometimes .env file can be missing.
just copy the .env.example file and paste in the same project folder with filename .env .
now run php artisan key:generate command. this will generate key for your application.
You can copy these files from template "blog" laravel
make sure app/storage dir permission is set to 755 and owner is set to admin. and also check permission and owner of files and dir in app/storage too
Create a new .env file and copy the code of .env.example and run the command -> php artisan key:gen
Rename the .env.example to .env
Go to bootstrap=>app.php and uncomment $app->withEloquent();
Make sure that APP_DEBUG=true in .env file.
Now it will work.
This worked for me:
Go to the .env file and be sure APP_DEBUG=true
Here (in .env file) change reemplace 127.0.0.1 for localhost for check if your DB credential are corrects.
Go to the config folder and do. the step #2.
in process of uploading env file to cpanel,
sometimes the dot is taken out and this may raised the error.
this solution worked for me.
go to your cpanel and rename env file to .env