drupal-project icon indicating copy to clipboard operation
drupal-project copied to clipboard

Drush internal commands do not inherit $_ENV

Open dotsam opened this issue 1 year ago • 1 comments

Some Drush commands will call exec() to run another Drush command (updatedb seems to be the main one, but there may be others). Somewhere in here either the load.environment.php from the Composer autoloader is not called, or $_ENV is clobbered in some way.

This was discussed in drush-ops/drush#4407 and the solution that worked for others, and works for me, is using $_SERVER in the settings.php file rather than $_ENV. The php.ini directive variables_order is referenced, and indeed, the comments for the directive indicate that in the php.ini-production file that most distros are based off of, Environment variables are not set by default.

The part I'm not clear on is that php-dotenv is manually populating the $_ENV global when it is called (via the autoloaded file), when a new drush process is exec()'d, it's not calling the Composer autoloader? But ENV vars from the parent process are copied into $_SERVER?

Ultimately, this issue is to see what should be done about $_ENV in .env.example, to see if it should be replaced with $_SERVER, getenv(), or just a note about the variables_order directive added.

dotsam avatar Jun 06 '24 21:06 dotsam

@dotsam I can confirm that phpdotenv in it's current implementation within this project does not work in some cases. We are discussing it in this issue https://github.com/drupal-composer/drupal-project/issues/379

AlexSkrypnyk avatar Jun 06 '24 23:06 AlexSkrypnyk