1

I took a Drupal project that was created awhile back via downloading a tar file and recreated it on a local via composer with drupal-project.

The recommended files were committed to git (i.e. no contributed modules, etc.) and cloned on the server. The composer install was clean.

At the point of doing a $ drush sqlc to load the database, it became evident that there was an issue - Drush error message below. I believe the issue is that Drush was already installed.

$ which drush outputs /home/me/.composer/vendor/bin/drush.

The error message when I attempt to run drush sqlc or drush status from the project, even with --root, is the following.

PHP Warning: require(/var/www/html/drupal/d8/vendor/composer/../../load.environment.php): failed to open stream: No such file or directory in /var/www/html/drupal/d8/vendor/composer/autoload_real.php on line 70 PHP Stack trace: PHP 1. {main}() /var/www/html/drupal/d8/vendor/drush/drush/drush:0 PHP 2. require() /var/www/html/drupal/d8/vendor/drush/drush/drush:4 PHP 3. include_once() /var/www/html/drupal/d8/vendor/drush/drush/drush.php:56 PHP 4. ComposerAutoloaderInit6220513682b217c143f76d07878222a3::getLoader() /var/www/html/drupal/d8/vendor/autoload.php:7 PHP 5. composerRequire6220513682b217c143f76d07878222a3() /var/www/html/drupal/d8/vendor/composer/autoload_real.php:60 PHP Fatal error: require(): Failed opening required '/var/www/html/drupal/d8/vendor/composer/../../load.environment.php' (include_path='/var/www/html/drupal/d8/vendor/pear/pear_exception:/var/www/html/drupal/d8/vendor/pear/console_getopt:/var/www/html/drupal/d8/vendor/pear/pear-core-minimal/src:/var/www/html/drupal/d8/vendor/pear/archive_tar:.:/usr/share/php') in /var/www/html/drupal/d8/vendor/composer/autoload_real.php on line 70 PHP Stack trace: PHP 1. {main}() /var/www/html/drupal/d8/vendor/drush/drush/drush:0 PHP 2. require() /var/www/html/drupal/d8/vendor/drush/drush/drush:4 PHP 3. include_once() /var/www/html/drupal/d8/vendor/drush/drush/drush.php:56 PHP 4. ComposerAutoloaderInit6220513682b217c143f76d07878222a3::getLoader() /var/www/html/drupal/d8/vendor/autoload.php:7 PHP 5. composerRequire6220513682b217c143f76d07878222a3() /var/www/html/drupal/d8/vendor/composer/autoload_real.php:60

In addition to Drush being in both ~/.composer/vendor and <root>/vendor, I note that ~/.composer contains

autoload.php
composer
phpdocumentor
phpunit
symfony
bin
doctrine
phpspec
sebastian

How do I go about cleaning this up so that the project root is the sole repository of these files and Drush can find what it's looking for?

3

As @Jaypan commented, globally you only need the Drush Launcher as phar file. And remove the old globally installed Drush version, this install method via composer global require is no longer supported. If you still need a legacy Drush version for other Drupal sites, download it the same way as phar file, see http://docs.drush.org/en/8.x/install. Which then can act as launcher by the way, so you don't need the Drush Launcher in this case.

  • Not to forget to simply call the local Drush directly: $ cd path/to/drupal-project && vendor/drush/drush/drush sql-dump > test.sql. – leymannx Aug 10 at 10:22
  • I removed the original drush that was not in the Drupal project. I installed the drush launcher (and renamed drush.phar to drush and did a chmod +x as instructed) in /usr/local/bin. When I run drush with or without the path, from within the Drupal site folder, I get the following (note the load.environment.php path with ../.. in the middle of it) – JAyenGreen Aug 10 at 15:33
  • PHP Warning: require(/var/www/html/drupal/d8/vendor/composer/../../load.environment.php): failed to open stream: No such file or directory in /var/www/html/drupal/d8/vendor/composer/autoload_real.php on line 70 – JAyenGreen Aug 10 at 15:33
  • PHP Fatal error: require(): Failed opening required '/var/www/html/drupal/d8/vendor/composer/../../load.environment.php' (include_path='/var/www/html/drupal/d8/vendor/pear/pear_exception:/var/www/html/drupal/d8/vendor/pear/console_getopt:/var/www/html/drupal/d8/vendor/pear/pear-core-minimal/src:/var/www/html/drupal/d8/vendor/pear/archive_tar:.:/usr/share/php') in /var/www/html/drupal/d8/vendor/composer/autoload_real.php on line 70 – JAyenGreen Aug 10 at 15:33
1

If you need global drush for legacy sites, and local drush for drupal-composer projects, then this may work for you.

I keep a copy of drush from Github, and fetch and checkout the latest 8.X.Y tag periodically. This executable is on my bash path.

For drupal-composer projects, I use direnv, and then put the following in my .envrc

PATH_add /home/mpdonadio/my-drupal-site/vendor/bin

Then when you cd into that directory, the vendor/bin for that project gets prepended to PS1, and that version of drush gets used. This lets me use Drush 9 for newer projects, and when combined with webflo/drupal-core-strict and drupal-core-require-dev you can avoid most dependency problems.

This approach also allows better control of drupal console, phpunit, and other dev executables; they gets added to the path and will pull in the same dependencies, and avoid update issues.

  • The final piece was copying load.environment.php to the project root. Not certain how it came to not be there, but putting it there resolved that error. – JAyenGreen Aug 10 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.