Move env config to root .env and make app_local.php optional - #1100
Move env config to root .env and make app_local.php optional#1100Chrishow2 wants to merge 3 commits into
Conversation
Infrastructure variables live in project-root .env (loaded by bootstrap); app.php reads them via env(). Installer creates .env and writes the salt there. app_local.php is no longer generated on install—copy from the example only when local overrides are needed.
|
While I'm a big fan of Tenet III of the 12-Factor pattern, this is a pretty big change to a file that hasn't changed in a major way since 2019. I don't think this can be part of v5, it might have to wait for v6. There are other repos that would need a similar update:
Not to mention the countless tutorials and Docker images that reference the current location of the file. What is the core problem you're trying to solve? If it's simply having environment variables defined and available in the root of your projects, direnv might be a solution worth looking into. |
|
Maybe make this PR for 6.x |
|
Thanks both, that makes sense. @jamisonbryant For me it's the mismatch between Cake's skeleton (config/.env) and what most tooling expects at the project root (Docker Compose, CI env injection, and the convention most PHP devs know from other frameworks). Agree the path change is too big for 5.x, and I hadn't fully accounted for the knock-on updates in app-api, app-tailwind, docs, and existing tutorials/Docker images. For 6.x I'm happy to include a migration note and help with the sibling repos if that's useful. @dereuromark For 5.next, I could do a minimal slice separately (docs and .env.example clarity, or whatever you have in mind) while keeping the root move for 6.x. Happy to retarget this PR or open a fresh one for 6.x, whichever you prefer. |
Summary
Moves environment configuration from
config/.envto a root.envfile, while keeping the stock CakePHP override layer optional..env.example→.env(created on install); loaded byconfig/bootstrap.phpconfig/app.phpreads infrastructure values viaenv()(database, salt, app URLs, etc.)SECURITY_SALTto.envinstead ofapp_local.phpapp_local.phpis no longer generated on install; developers can still copyconfig/app_local.example.phpwhen they want PHP-level local overridesWhy
.envis what most PHP projects, Docker Compose setups, and deployment tools expect.config/.envis easy to overlook and differs from other ecosystems contributors already use..envholds infrastructure/deployment variables;app_local.phpremains the optional CakePHP layer for application tuning (debug defaults, datasource tweaks).app_local.phpwith hardcoded datasource values, it could override or duplicate whatapp.phpreads from the environment. Makingapp_local.phpopt-in keeps.env→app.phpas the default path.Backwards compatibility / migration
Existing apps can move
config/.envto.envand delete the old file.app_local.phpcontinues to work if present. No change to bootstrap’s optionalapp_localload.Verified
.envand replaces__SALT__.envonly (noapp_local.php)app_local.example.php→app_local.phpstill overrides config