Managing Magento configuration across environments: config.php and env.php

Learn how to split Magento Open Source settings between shared config.php, machine-specific env.php and command-line secrets so every environment behaves predictably and nothing sensitive reaches Git.

On this page

Why Magento configuration drifts between environments and how to stop it

In a self-hosted Magento Open Source store, app/etc/config.php holds the shared settings that should look the same everywhere, while app/etc/env.php holds the machine-specific and sensitive settings such as database credentials, cache backends, session storage and encryption keys. Both files must be managed on purpose, because a store where settings differ between development, staging and production usually fails in one of two ways: a value changed by hand on production is lost on the next deployment, or a test setting leaks into the live store. Teams need this discipline as soon as they run more than one environment, build code on a separate pipeline, or lock production values so that administrators cannot change them from the admin panel. The same drift happens quietly in the configuration stored in the database, which is why the two files and the database must be reviewed together.

Drift usually starts with a simple habit: an administrator changes a setting in the admin, a developer edits env.php directly on a server, or a new module adds a value that exists only on one machine. Each change is reasonable on its own, but none of them reaches Git, so the next release behaves differently from the one tested. Before you design a process, inventory which settings belong to each file, which must differ per machine, and which must never be committed at all. Confirm the exact behavior of app:config:dump, locked values and command-line handling for sensitive settings against the Magento documentation for your installed version, since these mechanisms change between releases. Plan who owns each file, how changes are reviewed, and how production values are kept out of the repository, because these decisions determine how much of your release process depends on discipline rather than on tooling.

Which configuration method fits each type of setting

This table compares the four ways a Magento Open Source store receives configuration: exported shared settings, command-line settings with or without locking, environment or env.php values, and values saved in the admin. Read each row for when the method fits, who should own it, and the failure you most need to prevent.

MethodWhen it fitsWho should own itMain risk
app:config:dump into config.phpShared, non-secret settings that every environment should match, such as store scope defaults and module togglesPlatform or DevOps engineer, reviewed through the same pull request process as codeDumped values carry environment-specific entries if the dump runs on a developer machine with local URLs or test values
bin/magento config:set without lockingA value you want set once on a target environment and still editable later in the adminStore operations or the engineer running the release, with the command recorded in the runbookThe value is not reproduced on the next deployment, so the environment drifts from the documented state
bin/magento config:set with lockingA setting that must not change through the admin, such as a value a compliance control depends onSecurity or compliance owner signs off, platform engineer applies itLocked values can confuse admins who expect to edit them, and a locked change must be made through the command line or the file
Environment variables or env.php entriesSensitive values such as database credentials, encryption keys and third-party API secrets, plus host-specific settingsSecurity team owns the secret store, platform engineer maps variables into the environmentSecrets committed to Git or copied into shared documents, and env.php changes that are not backed up
Values saved in the adminDay-to-day content and merchandising settings that a store manager adjusts without a releaseStore manager or business owner, with admin access reviewed regularlyValues saved only in the database can revert or conflict after a deploy that re-imports shared config

How to set up a clean configuration workflow across environments

This sequence keeps shared settings identical across development, staging and production, keeps host-specific values and secrets out of version control, and ends with a repeatable check that confirms each environment resolves configuration the same way. Work through the steps in order, because each one depends on the inventory produced by the step before it.

  1. Inventory current settings per environment

    Ask the owner of each environment to list the settings that differ today, including base URLs, cache and session options, mail settings, payment and integration credentials, and any value changed in the admin. Record each setting with its scope and environment. On each host, run bin/magento config:show to capture the stored values and keep the output with the inventory. This step is done when every environment has a reviewed list and no team member can name a setting that exists only in someone's memory.

  2. Decide what is shared and what stays on each host

    Sort every inventory item into three groups: shared values that should match everywhere, host values such as database hostnames, cache backends and site hostnames that differ per machine, and secrets such as API keys, passwords and encryption-related values. Shared values belong in versioned configuration. Host values and secrets stay out of Git. Review the split with your security owner before any file changes. The output is a decision table that names an owner for each setting.

  3. Export shared settings with app:config:dump

    On a reference environment that already holds the agreed shared values, run bin/magento app:config:dump to write those settings into app/etc/config.php. Review the diff in the pull request and remove any line that holds a host value or a secret before merging. Deploy the file to a development environment and run bin/magento config:show for two or three keys from the decision table. This step is done when the values on the target match the reference environment.

  4. Lock production-only values

    Identify the settings that must not be changed through the admin on production, such as checkout or security options the team has approved, and lock them so the admin fields become read-only. Confirm the exact locking method for your Magento version in the configuration documentation before you apply it, because the procedure differs between configuration files and command options. Test the lock on staging first by attempting to change the value in the Stores Configuration screen. This step is done when the field is read-only in the admin and the locked value is still the effective value on the host.

  5. Set sensitive values from the command line on each host

    Set credentials and other secrets directly on each host with bin/magento config:set, using the path and scope recorded in your inventory, so the values never enter Git or a shared file. Run the commands from the account that owns the code, and keep the values out of shell history and CI logs. Keep the master copies in your team's secrets manager and confirm the storage location for each value in the configuration documentation. Confirm each value is set with bin/magento config:show on that host, without pasting the value into tickets or chat.

  6. Compare effective configuration across environments

    Add a check to your release pipeline or a scheduled job that runs bin/magento config:show on each environment, compares the output with the approved baseline, and flags any difference that is not in the decision table's host list. Review the report before each release window and record every deliberate exception with a named owner. This step is done when a deliberate change to a shared value appears in the report as expected and an undeclared change fails the check.

What never goes into Git and how to keep secrets out of the repository

Nothing that identifies a live environment or grants access to it belongs in Git. In a Magento Open Source store that means database credentials, the encryption key, admin and API tokens, mail and payment service credentials, and host-specific paths such as the document root, media mount points or local Redis and OpenSearch endpoints. The app/etc/env.php file holds most of these values and is the file most often committed by mistake, so it should appear in .gitignore from the first commit, and the repository should contain no copy of a production env.php in any branch or history. Confirm the exact file list your team ships with your Adobe documentation version before you write the ignore rules, because the set of generated and environment files changes across releases.

Inject secrets at deploy time rather than storing them in the build artifact. A common pattern is to keep the values in your CI system's protected variables or a dedicated secrets manager, render env.php on the production node during the deployment step, and set the file permissions so the web server user can read it but nobody else can. Sensitive settings can also be written with bin/magento config:set --lock-env from the command line on the server, so they stay out of files that move through the pipeline. Ask your partner or internal team to document which values come from which source, who can read each source, and how a build server without production access will still run static content deployment.

Review commits for leaks on a schedule and before merges. Run a secret scanner against the repository and its history, add it as a pre-commit or CI check, and review any change to app/etc/, .env files, auth.json and deployment scripts by hand. Magento's auth.json holds repository access keys for Adobe's package repository, so treat it as a credential. If a secret is committed, the fix is to rotate it, not only to delete it: generate a new database password, admin or API token, mail or payment credential, and, if the encryption key was exposed, plan the key change with the procedure in the hardening guide. Deleting the file from history does not help once a clone or fork exists. Record each rotation, the systems it touched, and the date it was completed.

Security and operational risks in configuration management

Configuration errors in Magento Open Source rarely announce themselves. A credential in a commit, a deploy that overwrites a live value, or a web user that can edit config files each creates a gap that persists until someone notices. The cards below pair each risk with the control that closes it and the team that should own it.

Secrets in Git history

Database passwords, encryption keys and mail or payment credentials committed to a repository stay in its history even after the file is deleted. Keep sensitive values in app/etc/env.php or the environment, keep that file out of version control, and add a secret scan to the pipeline. Owner: the engineering lead, with the security team reviewing history. Check the history of every branch, not only the current tree, and rotate any value that has ever been committed.

Magento 2 repository

Production values overwritten by a deploy

A deploy that copies a development config.php or shared settings file to production can replace live store settings, such as base URLs, cache backends or mail hosts, without warning. Separate shared settings from environment-specific ones and review the diff before every release. Owner: the release manager. Confirm which files the pipeline copies and which it skips on production nodes.

Locked settings nobody can explain

Values locked in env.php cannot be changed from the admin panel, so a store team may spend hours wondering why a change has no effect. Record why each lock exists, who set it and when it can be removed. Owner: the store operations lead. Ask the implementation partner for a list of every locked key at handover, with a reason next to each one.

Drift between web nodes

In a multi-node layout, each web server can end up with different configuration files, cache settings or Redis and session endpoints if they are edited by hand. Use one build artifact, one shared source for environment values and a check that compares configuration hashes across nodes after each deploy. Owner: the platform engineer. Confirm that the node-level check runs after every rollout, not only after incidents.

Admin changes lost on redeploy

Settings changed in the admin panel are stored in the database, but values written into config.php by app:config:dump or a deploy can later overwrite them. Decide which settings belong to code and which belong to the store team, and dump only the ones in code. Owner: the store operations lead and the developer who owns the deploy script. Test one admin change through a full staging-to-production cycle before relying on the process.

File permissions that let the web user edit configuration

If the web server user can write to app/etc, an attacker who exploits a vulnerability in the storefront can change configuration, add credentials or disable protections. Keep configuration files owned by the deploy user and readable, but not writable, by the web user. Owner: the infrastructure or security engineer. Verify permissions on every node after each release, and check that the admin cannot write to these files through the panel.

How configuration moves from development to production

Settings start in a developer's repository, where config.php holds shared, non-secret values that can be committed. The pipeline carries that file to the build and release stage without adding secrets. On each production host, env.php and sensitive values supplied from the command line stay inside the trust boundary. Check that nothing from the secrets side flows back into Git and that production values are never overwritten by a deploy.

Shared settings travel through the pipeline while secrets stay inside the boundary.

What to confirm in your environment before you standardize

Configuration standards for Magento Open Source only hold if they match your release line, your hosting platform, your secrets tooling and your extensions. The cards below list what to verify in your own environment, because each one changes where settings should live.

Behavior of your release line

Settings handling can differ between 2.4.x release lines, so the behavior you rely on should be checked against the version you run. Confirm the exact release and patch level in use, then read its release notes and the released versions list before you assume a config key behaves the same way. Verify on your target version, not on the version your developers last used. Record the result in your standard so the next upgrade starts from a known baseline.

Latest release line
2.4.9
Released versions

Environment variable injection by the host

Check whether your hosting platform, container runtime or orchestrator injects environment variables into the PHP-FPM or CLI process that runs Magento. Injected values can override or duplicate what is in env.php, and the precedence may differ between web requests, cron and CLI commands. Document which variables are set, where, and by whom, so a missing value does not silently change database or cache settings in production.

Secrets manager integration

Confirm how your secrets manager delivers database credentials, encryption keys, and mail or payment API keys to the Magento host. Find out whether secrets are written to files at deploy time, read at startup, or fetched by a sidecar, and who can rotate them. The chosen method decides whether env.php can stay free of plain-text credentials and how a rotation is applied without a manual edit on production.

Settings written by extensions

Extensions can write their own keys to config.php or to core_config_data through setup scripts, admin forms or install hooks. List every installed extension that stores configuration, and check which keys it writes and whether it expects them to be locked or dumped. An extension that writes to the database on production can drift from the file the team committed in Git, so this list belongs in your change review.

Locked values through upgrades

Ask whether your upgrade process keeps locked values intact. Test a copy of production with the upgrade steps you plan to use, then compare the resulting config.php and env.php with the expected files. Pay particular attention to locked settings, values set from the command line and any custom key that the upgrade tooling might reset or ignore. Adobe's upgrade guide names customizations and third-party integrations as drivers of upgrade effort, so budget verification time for them.

Upgrade guide overview

Who owns each setting

Decide who may change each class of setting: developers, platform operators or the business team using the admin panel. Confirm that your access model, change tickets and deployment pipeline match that decision, so a production change made in the admin does not bypass the process. Write the owner next to each key in your standard, since ownership decides which values belong in Git and which must stay out.

Questions teams ask before standardizing Magento configuration

Can our own team standardize Magento configuration without outside help?

Yes, if one or two engineers already know Magento's configuration files, have shell access to every environment and can own the repository. Teams with a small number of environments and few custom settings often manage it internally. Outside help tends to make sense when the team lacks Magento operations experience, when several environments drift apart, or when secrets have spread across hosts and chat tools. Ask yourself who will review changes to config.php after the first release, because that ongoing ownership is where internal efforts usually stall.

What drives the effort of a configuration standard?

Effort rises with four factors: the number of environments (development, staging, production and any build or QA systems), the number of installed extensions that add their own settings, the number of custom settings your business depends on, and how mature your deployment pipeline is. A store with one production host and a manual release process needs a simpler standard than one with separate build and production systems and several web nodes. Ask for the work to be scoped against an environment inventory and a list of extensions, since those two documents determine most of the cost.

What do we need to provide before the work starts?

Plan to provide four things: SSH or equivalent access to each host that runs Magento, ownership or admin rights for the Git repository that will hold shared configuration, and an inventory of every secret the store uses. The secrets inventory should list database credentials, encryption keys, mail and payment credentials, search and cache passwords, and any API tokens, along with where each one lives today. Your team should also name a decision-maker who can approve which settings are shared and which stay local. Missing items usually show up as delays in the first week.

How long will it take to standardize our configuration?

Duration depends on the written scope, not on a general rule. The main variables are the number of environments, how many settings are currently set by hand, how many secrets need to move, and whether the release pipeline must change at the same time. Ask any provider to break the timeline into discovery, inventory, the shared configuration build, secret migration, and verification on each environment, and to state which items are included and excluded. Compare quotes on that breakdown, and check that each phase has a defined end point.

Should env.php be kept in Git?

No. The app/etc/env.php file holds database credentials, the encryption key, cache and session connection details and other values that differ per host or that must stay private. Keep it out of Git, generate or write it on each host from a secure store, and restrict its file permissions so the web server user can read it but the wider system cannot. Shared, non-secret settings belong in config.php, which can be committed and deployed as code. Confirm the exact file behavior against the Magento documentation for your version before changing your deployment.

How does a configuration standard change after an upgrade?

An upgrade can change which settings exist, which defaults apply and how some values are stored, so the standard needs a review after every patch or minor release. Adobe's upgrade guidance names extensions, third-party integrations and custom code as the main drivers of upgrade effort, and those are the same items that add configuration. Keep the shared configuration file in version control so the diff shows exactly what changed, run the configuration dump and compare step again on a staging copy, and confirm that secret values still load from the secure store. Plan this check as a recurring task, not a one-time project.

What goes wrong when configuration is not standardized?

The most common failure is drift: a setting changed on one host through the admin panel or the command line never reaches the others, so staging and production behave differently. Other failures include secrets committed to Git history, which then need rotation, and a release that fails because a required value exists only on one server. Check that every environment can be rebuilt from the repository plus the secure store, and test that a new node starts with the same settings as the existing ones before you rely on the standard.

Where to read the official Magento configuration and release documentation

Start with the Adobe Commerce PHP development overview for the code-level picture of how configuration reaches the application. Read it alongside the configuration files and their precedence that this topic describes, so you can match the vocabulary Adobe uses for modules, themes and settings to the config.php and env.php files in your own repository. The overview also explains the component types that extend Magento Open Source, which helps you decide which settings belong to a custom module and which belong to the shared environment. Use it as the reference when your developers ask why a value is stored in one file and not another.

Next, read the Adobe Commerce upgrade guide overview before you change how configuration is managed. Adobe names customizations, third-party integrations and coding practices as drivers of upgrade effort, and configuration drift is a common reason an upgrade takes longer than planned. The guide also references the Upgrade Compatibility Tool, which is worth running against your custom modules before a patch cycle. Ask whether your configuration layout survives a version move without manual edits, because that answer shapes your release runbook.

Check every configuration detail against the exact release you run. Adobe's pages cover several 2.4.x lines with different support dates and requirements, so a setting or command shown in a guide may differ between 2.4.8 and 2.4.9. Record the version you deploy in your change records, confirm the matching documentation version in the Adobe pages, and retest configuration changes in staging before production. If a setting is not described for your release, confirm it with Adobe support or in the source before relying on it.

How DeployOpen scopes and delivers configuration management

DeployOpen plans and builds the configuration layout for your Magento Open Source store inside your own infrastructure, so that shared settings, environment settings and secrets each have a defined home. The work is scoped in writing before it starts, and the result is documented so your team can review and operate it.

How we scope

  • Inventory which settings are shared, which differ per environment, and which are secrets, across development, staging and production.
  • Agree in writing which files and sources of truth the layout uses, including config.php, env.php and the deployment pipeline.
  • Confirm the list of settings to lock, the sensitive values to set from the command line, and the Git rules that apply to each file.

How we build

  • Configure the shared settings with app:config:dump and review the generated config.php changes before they are committed.
  • Set environment-specific and sensitive values through the command line and keep them out of version control.
  • Test that each environment loads the expected values and that locked settings cannot be changed from the admin panel.

How we hand over

  • Deliver a written runbook covering the file layout, the commit rules, the .gitignore entries and the steps to add a new environment.
  • Document the command sequence for promoting configuration changes from development to production with your team.
  • Walk your engineers through the review checklist so each configuration change is checked before it reaches production.

How we support

  • Provide ongoing support and upgrades as a retainer when your store needs configuration changes after launch.
  • Re-check the configuration layout when you move to a new Magento Open Source release line or add a new environment.
  • Confirm with your team which changes need a fresh review, so that retainer hours match the changes you actually plan to make.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.