drupal-composer / drupal-project

:rocket: Composer template for Drupal projects. Quick installation via "composer create-project drupal-composer/drupal-project"
GNU General Public License v2.0
1.56k stars 941 forks source link

Drush internal commands do not inherit $_ENV #674

Open dotsam opened 3 months ago

dotsam commented 3 months ago

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.

AlexSkrypnyk commented 3 months ago

@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