[wp-trac] [WordPress Trac] #63543: Environment variable WP_CONFIG_PATH should be to cli container in wordpress-develop env
WordPress Trac
noreply at wordpress.org
Fri Jun 6 20:49:39 UTC 2025
#63543: Environment variable WP_CONFIG_PATH should be to cli container in
wordpress-develop env
------------------------------+--------------------
Reporter: westonruter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.8.2
Component: Build/Test Tools | Version:
Severity: normal | Keywords:
Focuses: |
------------------------------+--------------------
I'm working on a
[https://gist.github.com/westonruter/631424e1b7f387a28c349c35437aaf15
multi-environment setup] where I can have plugins cloned into `src/wp-
content/plugins` which use wp-env for their development/test environments,
but also using the core files in wordpress-develop. At the same time that
the wp-env environments can be running for these plugins, I intend for the
wordpress-develop Docker environment to also be able to run. In order for
this to work, there's currently some footwork needed.
The core issue is that wp-env will create a `wp-config.php` at `ABSPATH`
which it uses for its environments, but the wordpress-develop environment
uses the `wp-config.php` which is one directory above. To work around
this, the `wp-config.php` created by wp-env is modified to add the
following at the top:
{{{#!php
<?php
// Load the wp-config.php for wordpress-develop when the current request
is coming from that environment.
if ( basename( __DIR__ ) === 'src' && file_exists( __DIR__ . '/../wp-
config.php' ) ) {
require_once __DIR__ . '/../wp-config.php';
return;
}
}}}
This does not work in the CLI container, however, because of how WP-CLI
[https://github.com/wp-cli/wp-
cli/blob/2800ad0a66747a826ae4221b2f022f1df6779cb6/php/WP_CLI/Runner.php#L742-L783
reads the config] during bootstrapping. An error results when trying to
run WP-CLI:
{{{
Warning: Constant WPINC already defined in /var/www/src/wp-settings.php on
line 16
Fatal error: Cannot redeclare _wp_can_use_pcre_u() (previously declared in
/var/www/src/wp-includes/compat.php:33) in /var/www/src/wp-
includes/compat.php on line 33
}}}
Therefore, there needs to be another way to force WP-CLI to use a
different `wp-config.php`, and the `wp_locate_config()` function
[https://github.com/wp-cli/wp-
cli/blob/2800ad0a66747a826ae4221b2f022f1df6779cb6/php/utils.php#L328-L329
provides this] via the `WP_CONFIG_PATH` environment variable. The
remaining issue then is how to pass this environment variable into the CLI
container. Adding it to `.env` is not enough apparently, as it seems it
must be added specifically to `docker-compose.yml`, for example:
{{{
diff --git a/docker-compose.yml b/docker-compose.yml
index 48f3abc607..172c406b4b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -106,6 +106,7 @@ services:
PHP_FPM_UID: ${PHP_FPM_UID-1000}
PHP_FPM_GID: ${PHP_FPM_GID-1000}
HOST_PATH: ${PWD-}/${LOCAL_DIR-src}
+ WP_CONFIG_PATH: ${WP_CONFIG_PATH-/var/www/wp-config.php}
volumes:
- ./:/var/www
}}}
Doing this ensures that the wordpress-develop environment uses the
expected `wp-config.php` in the repo root.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63543>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list