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

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!



Solution 1:[1]

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!

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

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

Solution 7:[7]

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

Solution 8:[8]

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');
}

Solution 9:[9]

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

Solution 10:[10]

Don't do this line until you have keys in a specific location for the file

in AuthServiceProvider.php

//Passport::loadKeysFrom('/secret-keys/oauth');

Solution 11:[11]

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.