Make WordPress Core

Opened 7 years ago

Last modified 21 months ago

#41710 new enhancement

optionally obtain WP_* configuration constants from the environment

Reported by: drzraf's profile drzraf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.1
Component: Bootstrap/Load Keywords: 2nd-opinion
Focuses: Cc:


Although hardcoding strings inside a configuration is the traditional way to setup applications, having smooth configurations values is sometimes needed.

The context of rising CI/virtualization/automated WP deployments increases the need of provisioning WP configuration (setup and adjunst DB credentials/debug-mode/site-url/... in an easy and flexible manner).

wp-config.php currently imposes harcoding string values in a PHP-formatted regular text file. No file override, no override of the source of the values.

This creates coding horrors where people almost invent sed/awk-based PHP macro templating systems to simply configure a WP instance.

The fact that wp-config.php uses PHP-format rather than ini/yaml is not the issue.
The issue is that the current configuration does not offer the possibility of environment indirection.
(the other "issue" being that developers are reluctant to create a modified copy of wp-config-sample.php getenv()-based, maybe to be future-proof in case of wp-config.php changes, maybe to respect user-provided changes)

In the Unix world, environment has been the traditional and flexible way to transmit information to child processes.

Is there any blocking wp-config.php from fetching some or all of its user-defined constants from the environment out of the box?
Would maintainers consider such an enhancement?

Some suggestions (among many possible others):

  1. fetch from getenv() if wp-config.php is absent
  2. fetch from getenv() if mandatory values of wp-config.php values are empty
  3. fetch from getenv() even if wp-config.php values are empty
  4. load wp-config.$HOSTNAME.php if present
  5. load wp-config.{PHP_SAPI}.php if present
  6. provide (and maintain) a wp-config-env-sample.php getenv()-based
  7. ...

related forum post

Change History (3)

#1 @marsjaninzmarsa
7 years ago

  • Keywords 2nd-opinion added

To be honest...

Nothing blocking you from fetching from env in your installs, providing generic wp-config.php in way presented in forum topic. Nothing blocking anyone from implementing such flow, current configuration system is flexible enough to offer the possibility of environment indirection, and in the same time simple enough to be handled even by atechnic user (via various installers, wizards and creators, internal or 3rd party, and even directly), so as much I like an idea, I don't see need for any additional support from Core.

#2 @johnbillion
5 years ago

  • Component changed from Build/Test Tools to Bootstrap/Load

#3 @xavivars
21 months ago

I do think the benefit of supporting something like this from core would be significant.

If wp-config (or even wp-config-sample) would look closer to than to current wp-config, it would be easier to inject configuration via environment variables

Note: See TracTickets for help on using tickets.