oauth-private.key does not exist or is not readable - php

So, I imported another project from Bitbucket and tried to launch it using php artisan serve, I always get this error:
[LogicException]
Key path "file:///var/www/html/DesignViewer5/storage/oauth-private.key" does not
exist or is not readable
I don't get this error when I make a project myself, I can't run any other command. I tried 'php artisan key:generate', and got the exact same error.
I tried: composer update, and got this:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
- Updating spatie/laravel-permission (1.11.1 => 1.12.0) Downloading: 100%
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
[LogicException]
Key path "file:///var/www/html/DesignViewer5/storage/oauth-private.key" doe
s not exist or is not readable
Script php artisan optimize handling the post-update-cmd event returned with error code 1
Anyone knows how to fix it? Thanks!

I think that this is due to Laravel Passport, you should try the following command:
php artisan passport:install
This command will create the encryption keys needed to generate secure
access tokens. In addition, the command will create "personal access"
and "password grant" clients which will be used to generate access
tokens
Source: https://laravel.com/docs/5.4/passport

I had the same problem when I updated the composer.I generated the keys again using php artisan passport:keys and it solved the problem

I found the solution
Solution:
In config/app.php I had to comment these lines:
/*Laravel\Passport\PassportServiceProvider::class,
App\Providers\CodeGrantProvider::class,
Spatie\Permission\PermissionServiceProvider::class,*/
Than you need to migrate the whole database again,
than uncomment this line:
Laravel\Passport\PassportServiceProvider::class,
And run php artisan passport:install my application keys weren't working so I had to do:
php artisan config:clear
php artisan key:generate
php artisan config:clear
And than I could do php artisan serve
Thanks!

so sample if you already install passpord and don't config run this command
php artisan passport:keys
If already doesnt install the passport package you must check the docs of passpord in Laravel docs

Step 1:
Only Run if oauth-private.key and oauth-public.key not exists in
storage folder otherwise skip first step..
php artisan passport:install
Step 2:
Clear configration and generate key
php artisan config:clear
php artisan key:generate
php artisan config:clear
Step 3:
Change permission and owner like that :
sudo chown www-data:www-data storage/oauth-*.key
sudo chmod 600 storage/oauth-*.key

Since /storage/*.key is in .gitignore so if you pull the project, that might be missing the key by running php artisan passport:keys will generate new keys for you.

Run: php artisan passport:install.
If get message like "Encryption keys already exist. Use the --force option to overwrite them."
Then run
Run: php artisan config:clear
Run: php artisan key:generate.
And finally
Run: php artisan config:clear

I have removed this bit: Passport::loadKeysFrom(__DIR__.'/../secrets/oauth');
from App\Providers\AuthServiceProvider and it fixed the issue.
https://laravel.com/docs/8.x/passport#deploying-passport
/**
* Register any authentication / authorization services.
*
* #return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::loadKeysFrom(__DIR__.'/../secrets/oauth');
}

if you use heroku as deployment,
try add this in composer.json at the script line
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 777 storage",
"php artisan passport:keys"
]
and then run this command
php artisan passport:install
php artisan config:clear
php artisan optimize

do this commands
sudo chown www-data:www-data storage/oauth-*.key
php artisan passport:install
php artisan config:clear
php artisan key:generate
php artisan config:clear

Don't do this line until you have keys in a specific location for the file
in AuthServiceProvider.php
//Passport::loadKeysFrom('/secret-keys/oauth');

for my after i run composer install passport is already installed so php artisan passport:install does not help.
try to touch new file (oauth-private.key) to storage dir, then run command
php artisan passport:keys --force
this command 'll force override private key you touched and create "aouth-public.key" file. it 'll work fine

Depending on the environment you are using to deploy. If, for example, you are using a Heroku deploy, you may have to remove the folder containing the keys from gitignore before pushing and then later add it back. This worked for me after following the steps above.

firstly, search in oath-private-key in your application folder. copy
it and go to App/provider folder. create a new folder , secret and
oauth like that
App/Provider/Secret/Oauth and paste your oath-private-key here.
I hope it helps you.

For Windows OS. If you have already installed passport, or you are setting up an existing application and then facing this problem then try "php artisan passport:keys"

Related

Why does my laravel app request favicon.ico? [duplicate]

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.

Getting Error 500 after composer update from ssh

I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
run composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve

php artisan migrate nothing to migrate error

I am trying to install this package on my server after installing everything when I try to migrate with php artisan migrate it tells me there is nothing to migrate. Also the migration table is not there. here is what I did:
php composer.phar require igaster/laravel_cities
change in providers app.php
Igaster\LaravelCities\GeoServiceProvider::class,
Ran this script
mkdir storage/geo
cd storage/geo
wget http://download.geonames.org/export/dump/allCountries.zip && unzip allCountries.zip && rm allCountries.zip
wget http://download.geonames.org/export/dump/hierarchy.zip && unzip hierarchy.zip && rm hierarchy.zip
Now when I run php artisan migrate it tells me there is nothing to migrate
I am not sure if this is because I have php composer.phar instead of composer?
Try php artisan config:cache then retype php artisan migrate - Hope this helpfull...
Try running:
php artisan vendor:publish --provider="Igaster\LaravelCities\GeoServiceProvider"
And then run the migration
php artisan migrate
php composer.phar is identical to composer so thats not the issue.
If migration file not showing you likely need to run
php artisan vendor:publish
Copy vendor/igaster/laravel_cities/src/migrations folder contents to database\migrations folder, then run php artisan migrate. Sometimes publishing vendor resources doesn't work for me too and I dive into the source of the package then to make them work.

No Application Encryption Key Has Been Specified

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.

How do I remove old artisan command from Kernel in Laravel 5

I have created some Command files into my Laravel Application. Laravel version is 5.2. I set command like: get:email in the Command file. Also call the Command file into Kernel.php. After that I can see the artisan command list by typing the command php artisan list. as like as below:
//output
get:email
And I changed the command title get:email to get-bq:email. When I run the command php artisan get-bq:email -- its working nicely. Also I can see the list by typing the command php artisan list::
//output
get-bq:email
Issue / Problem: Both commands are working. But I won't to work with both of them. I have done the following things:
modified command file as well as command
run composer dump-autoload -o
run composer update
remove vendor and storage folder then run composer update again.
Still the old command is working into my system.
What I want: How May I remove my old commands from my Laravel(5.2) application?
Run these commands:
php artisan cache:clear
php artisan config:clear
These commands will clear app cache and config cache and recreate it.
I've had the same problem recently.
Repoeatedly tried
php artisan cache:clear
php artisan config:clear
and the cached Kernal command wouldn't clear.
In desperation i killed the queue worker terminal and restarted the queue with the command
php artisan queue:work
The issue stopped.

Categories