Laravel Passport cannot find or read its oauth key files
Key path oauth-private.key does not exist or is not readableShort answer
Passport signs tokens with a key pair and cannot start without it. The keys are normally kept out of source control, so a fresh server has none. Run php artisan passport:keys on that server. If your keys live elsewhere, point Passport at them with Passport::loadKeysFrom, or load them from PASSPORT_PRIVATE_KEY and PASSPORT_PUBLIC_KEY.
Fix it fast
1Find out which cause you have
Look at the path in the message, then look for the key files on the machine that threw the error. This tells you whether they are simply absent.
find . -name "oauth-*.key" -not -path "./vendor/*"2Match what you see, then jump to its fix
- 1
find lists no oauth-private.key and no oauth-public.key; typical right after a first deploy or a fresh cloneThe key pair was never generated on this serverFix - 2
The keys exist in one folder, but the error names a different oneThe app was told to read the keys from another folderFix - 3
No key files anywhere, because the project stores the keys in the environment, and the variables are missing on this serverThe keys are meant to come from environment variables, but those are not setFix
- 1
What does the error look like?
Key path oauth-private.key does not exist or is not readableKey path oauth-public.key does not exist or is not readable
Cause 1 of 3
The key pair was never generated on this server
1Check
The Passport docs say the generated keys are not typically kept in source control, so every new server has to create its own. Look in the folder named in the error.
git status --ignored --short | grep oauth2Fix
Run the key command once on the server, as part of the first deployment.
php artisan passport:keys3Verify
Both files now exist, and the request that failed no longer raises the key error.
find . -name "oauth-*.key" -not -path "./vendor/*"Confirmed by laravel.com
Cause 2 of 3
The app was told to read the keys from another folder
1Check
Search the app for a Passport::loadKeysFrom call. If one exists, Passport looks only in that folder, so keys left in another folder are ignored.
grep -rn "loadKeysFrom" app/ bootstrap/ config/2Fix
Either create the keys in the folder named in loadKeysFrom, or fix the path in the AppServiceProvider boot method so it points at where the keys really are.
// app/Providers/AppServiceProvider.php
public function boot(): void
{
Passport::loadKeysFrom(__DIR__.'/../secrets/oauth');
}3Verify
The folder you passed to loadKeysFrom contains both key files.
ls -l secrets/oauth/Confirmed by laravel.com
Cause 3 of 3
The keys are meant to come from environment variables, but those are not set
1Check
After publishing the Passport config file, the keys can be supplied through PASSPORT_PRIVATE_KEY and PASSPORT_PUBLIC_KEY. Confirm the config is published and the two variables exist.
ls config/passport.php
grep -c "PASSPORT_" .env2Fix
Publish the config if it is missing, then put the full PEM text of both keys into the server's environment.
php artisan vendor:publish --tag=passport-config
# .env
PASSPORT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
<private key here>
-----END RSA PRIVATE KEY-----"
PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
<public key here>
-----END PUBLIC KEY-----"3Verify
Retry the token request that failed.
php artisan config:show passportConfirmed by laravel.com
How do I stop it coming back?
- Add php artisan passport:keys to the first-deploy checklist for every new server.
- Keep the private key out of git, and store it in your secret manager if servers are rebuilt often.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix