wordpress icon indicating copy to clipboard operation
wordpress copied to clipboard

Add WP_DEBUG_LOG and SCRIPT_DEBUG to Docker Env variables

Open deeptiboddapati opened this issue 3 years ago • 1 comments

I like running WP files as readonly and managing their configuration with Docker Env variables. WP_DEBUG_LOG and SCRIPT_DEBUG are two WP constants that are important to set if I want to debug code. I will especially need WP_DEBUG_LOG to make sure production errors are logged but not shown to visitors. Right now, the package allows for an env variable to be passed through for WP_DEBUG but not these other two important debugging parameters.

deeptiboddapati avatar Dec 05 '22 11:12 deeptiboddapati

I would suggest using WORDPRESS_CONFIG_EXTRA for this (you provide it arbitrary PHP code that gets evaluated as part of wp-config-docker.php).

tianon avatar Dec 05 '22 21:12 tianon

I would suggest using WORDPRESS_CONFIG_EXTRA for this (you provide it arbitrary PHP code that gets evaluated as part of wp-config-docker.php).

I think the problem is the php error when trying to "redefine" the constants. Having a look into the wp-config.php inside the container reveals that you have the option to define your config via WORDPRESS_CONFIG_EXTRA:

// (we include this by default because reverse proxying is extremely common in container environments)
if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) {
        eval($configExtra);
}

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );
define( 'SAVEQUERIES', true );
define( 'WP_DEBUG_DISPLAY', false );
/* That's all, stop editing! Happy publishing. */

but trying to redefine a constant is still an error which shows with the wp-debugging plugin: chrome_iRC68FNVAA

It would be nice if those can be overwritten by ENV variables like those lines: define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') );

Supportic avatar Mar 22 '23 22:03 Supportic

Those extra define lines aren't from our config file:

https://github.com/docker-library/wordpress/blob/f7f171e0e6bec88ffa0edd58ca1c512d286ab18d/wp-config-docker.php#L121-L125

tianon avatar Mar 22 '23 22:03 tianon

Those extra define lines aren't from our config file:

https://github.com/docker-library/wordpress/blob/f7f171e0e6bec88ffa0edd58ca1c512d286ab18d/wp-config-docker.php#L121-L125

Sorry I just realized that one of those plugins: "debug-bar, query-monitor, wp-debugging" are injecting those ENV vars. Should work as expected then. 👍

Supportic avatar Mar 22 '23 22:03 Supportic

Closing as this seems solved.

yosifkit avatar Aug 10 '23 18:08 yosifkit