New environment variables not injected into container (Dockerfile + FrankenPHP)
marlon12-dc
FREEOP

a month ago

Issue:

Environment variables I add in the dashboard are NOT reaching my container at runtime. A newly added variable TEST_VAR=hola is not visible from PHP via $_ENV, getenv(), or Laravel's env(). However, older variables like DB_* DO work correctly.

What I've verified:

  • The variable IS present in the dashboard for the correct service (the app service, not Postgres).
  • I tried both the individual editor and the Raw Editor.
  • I triggered a fresh "Deploy latest commit" after adding the variable, and waited for Active.
  • A debug route confirms: env('DB_DATABASE') = OK, but env('BCCR_SDDE_TOKEN') and env('TEST_VAR') are empty.
  • $_ENV shows 84 total variables, but my newly added ones are not among them.
  • No .env file is committed to the repo. No config cache present.

Setup:

  • Laravel 12 app served with FrankenPHP via a custom Dockerfile.
  • Start command runs artisan migrate + view:cache, then frankenphp run --config /etc/caddy/Caddyfile.

Question:

How do I make newly added runtime environment variables available to the PHP process inside the container? Why do older variables work but new ones don't get injected?

$10 Bounty

1 Replies

Railway
BOT

a month ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway • about 1 month ago


turicamirabelamaria-art
PRO

a month ago

Your FrankenPHP/PHP setup is probably not the problem.

Railway variable edits are staged configuration changes. Deploy Latest Commit deploys the GitHub source, but it does not apply unrelated staged changes. That matches your symptoms exactly: the older DB_* variables are part of the deployed configuration, while the newly added variables are visible in the dashboard but absent from the running container.

Open the pending/staged changes in the Railway environment and deploy/apply that changeset. Wait for the resulting deployment to become active.

Then verify inside the new deployment with:

printenv | grep TEST_VAR

and/or:

php -r 'var_dump(getenv("TEST_VAR"));'

You should not need to add the variable with ENV in the Dockerfile or commit a .env file. Railway service variables are injected into the running deployment at container startup, and FrankenPHP exposes normal process environment variables to PHP.

If the staged changes panel is empty and the variable is still missing after a deployment generated by applying the variable change, then check that the variable belongs to the exact same service + environment as that deployment.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...