Unable to read oauth-public.key for passport - laravel app

I am experiencing a weird issue, I have created a volume (Persistent storage) for my Storage folder as mentioned in docs. to keep my storage persistent. but I noticed a weird issue where I get "Exception Message:\n\nUnable to read key from file file:///var/www/html/storage/oauth-public.key"

This exception occurs intermittently.

Any clue what’s going on? and How to solve this issue?


It’s strange it occurs intermittently. Either the file is readable … or it isn’t :thinking:

I’d start by checking the file exists and that it has the correct permissions. SSH in to the vm …

… and then take a look in /var/www/html/storage (as that’s where it’s expecting the file to be, based on that error message).

Is it there?

If not you could maybe do a fresh install of passport php artisan passport:install I’d think that should make new ones.

If you do have a key file, does it have the correct permissions? I’d think you’d want 600

chmod 600 /path/to/oauth-private.key

If Laravel is still not happy … do you have the correct APP_URL and APP_STORAGE value in your env? That’s worth checking.

Also, try clearing any cache:

php artisan config:clear

I’d guess some combination of those should fix it. Unless there is some hardware weirdness going on with that volume.

Yes I can confirm it’s there. What APP_STORAGE value would be like? cauze it’s not in my fly.toml file enviroment variables.

And I did the previous steps you mentioned. I’ll be back with results.


Ah, ok, yep that APP_STORAGE path seems like it’s just if you needed to mess with the default storage path e.g


But that shouldn’t be needed. Passport should make a file at the correct location, the default path. It’s more likely a permissions issue where the file is there, but can’t be read.


Can you share your fly.toml?

If you’re defining multiple processes (cron/queue other stuff might be under [processes] in your fly.toml), the VMs running those commands won’t have your volume attached, which could cause such an error.

Other debugging questions: Does the error happen during a deployment, or just randomly when running? Do you see it in the fly logs, or using an exception tracker? (Sentry, bugsnag, whatever).

# fly.toml app configuration file generated for academy-de on 2023-09-30T11:00:04+03:00
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.

app = "academy-de"
primary_region = "fra"
console_command = "php /var/www/html/artisan tinker"


    NODE_VERSION = "18"
    PHP_VERSION = "8.2"

  LOG_CHANNEL = "stderr"
  LOG_LEVEL = "info"
  LOG_STDERR_FORMATTER = "Monolog\\Formatter\\JsonFormatter"

  internal_port = 8080
  force_https = true
  auto_stop_machines = false
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

This is my fly.toml I gave it the permission, it didn’t work

When I try to fetch some data I got the error as an alert in the browser. and it heppends randomly yeah

You can provide the passport keys as environment variables instead of files. This is generally much simpler in a container environment.

The expected variables are PASSPORT_PUBLIC_KEY and PASSPORT_PRIVATE_KEY. You could add them as fly secrets.

I’ll give it a shot, but Why the volumes sometimes returns an 404 error code, if multiple requests made to a certain files at a time like ( 1000 Request ). any clue?


The volumes aren’t network based or anything, and it’s mounted before each VM starts so it SHOULD not be the case that a file is missing.

I suspect we’ll find out there’s something going on in the code (making assumptions about file path) or something else going on, like something configured (a background process via supervisord?) to run in a way that doesn’t pick up the right file path.

Now the biggest clue we have here I think is that you’re seeing an error in the browser, not on the server-side (is that correct?)

I’m not sure if you’re being literal with calling it a 404 code (that’s an HTTP response, not a file system error). Assuming you just mean the code is not finding that file and the server is responding with an error saying that file is not found, I’m a bit suspicious that you only see it from a request happening in the browser.

:bulb: Any chance a client-side code is hard-coded to like localhost or something that just happens to work on your machine (bc you have the dev server running locally) or something funky like that?

:point_right: It’s possible the deploy step (which runs a docker build... isn’t using the right hostname when building static assets that might point to a URL. If any javascript uses process.ENV.foo to pick up env vars, for example, that’ll need to be set as an env during build-time, usually via a build argument.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.