60

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!

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
O'Niel
  • 1,622
  • 1
  • 17
  • 35

15 Answers15

124

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

Hammerbot
  • 15,696
  • 9
  • 61
  • 103
38

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

  • 1
    most useful when you deploy it server, doesn't want to reinstall passport – sumit sharma Jun 07 '19 at 06:08
  • php artisan passport:install will not reinstall passport... If it is already installed it will skip the installation and generate the keys... – Vagabond Feb 19 '20 at 11:33
19

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!

O'Niel
  • 1,622
  • 1
  • 17
  • 35
18

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

Rahman Rezaee
  • 1,943
  • 16
  • 24
11

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
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
10

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.

shivanisdev
  • 687
  • 6
  • 16
6
  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
Lokman Hosen
  • 342
  • 5
  • 6
4

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');
}
phoenixstudio
  • 1,776
  • 1
  • 14
  • 19
Dgloria
  • 161
  • 1
  • 12
3

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
Ricky Anwar
  • 109
  • 1
  • 5
3

For me 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

1

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
Ahmed Safadi
  • 4,402
  • 37
  • 33
1

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

in AuthServiceProvider.php

//Passport::loadKeysFrom('/secret-keys/oauth');
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
amine ghandi
  • 29
  • 1
  • 6
0

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.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Sola
  • 1
0

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.

Kusursuz
  • 39
  • 7
0

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"

Saad
  • 105
  • 1
  • 12