oauth-private.key 不存在或不可读

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

所以,我从 Bitbucket 导入了另一个项目并尝试使用 php artisan serve 启动它,我总是得到这个错误:

[LogicException]                                                                   
  Key path "file:///var/www/html/DesignViewer5/storage/oauth-private.key" does not   
  exist or is not readable                                                           

我自己做项目时没有出现这个错误,我不能运行任何其他命令。我试过 'php artisan key:generate',得到了完全相同的错误。

我尝试了:composer update,得到了这个:

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

有人知道怎么解决吗?谢谢!

我认为这是由于 Laravel Passport,您应该尝试以下命令:

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

来源:https://laravel.com/docs/5.4/passport

我找到了解决办法 解决方案: 在 config/app.php 我不得不评论这些行:

/*Laravel\Passport\PassportServiceProvider::class,
App\Providers\CodeGrantProvider::class,
Spatie\Permission\PermissionServiceProvider::class,*/

比起你需要再次迁移整个数据库, 比取消注释这一行:

Laravel\Passport\PassportServiceProvider::class,

并且 运行 php artisan passport:install 我的应用程序密钥无法正常工作,所以我必须这样做:

php artisan config:clear
php artisan key:generate
php artisan config:clear

我做不到php artisan serve

谢谢!

执行此命令

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

当我使用 php artisan passport:keys 更新 composer.I 再次生成密钥时,我遇到了同样的问题,它解决了问题

在文件的特定位置有密钥之前不要执行此行

AuthServiceProvider.php

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

第 1 步:

Only Run if oauth-private.key and oauth-public.key not exists in storage folder otherwise skip first step..

php artisan passport:install

第 2 步:

Clear configration and generate key

 php artisan config:clear
 php artisan key:generate
 php artisan config:clear

第 3 步:

Change permission and owner like that :

sudo chown www-data:www-data storage/oauth-*.key
sudo chmod 600 storage/oauth-*.key

由于 /storage/*.key.gitignore 中,因此如果您拉取项目,可能会丢失 运行 的密钥 php artisan passport:keys 将为您生成新密钥。

我删除了这个位:Passport::loadKeysFrom(__DIR__.'/../secrets/oauth'); 来自 App\Providers\AuthServiceProvider,它解决了问题。

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');
}
  1. 运行: php artisan passport:install。 如果收到类似“加密密钥已存在。使用 --force 选项覆盖它们”的消息。 那么运行
  2. 运行: php artisan config:clear
  3. 运行: php artisan key:generate。 最后
  4. 运行: php artisan config:clear

如果你已经安装了 passpord 并且没有配置 运行 这个命令

php artisan passport:keys

如果还没有安装 passport 包,你必须在 Laravel docs

中查看 passpord 的文档

取决于您用于部署的环境。例如,如果您使用的是 Heroku 部署,则可能必须在推送之前从 gitignore 中删除包含密钥的文件夹,然后再将其添加回去。按照上述步骤后,这对我有用。