Optimising your Drupal CLI tools
It has become best practise to install a separate version of Drush and Drupal Console for each project you work on. The advantages of this are that your CLI tools are always compatible with the site you are building, and that any dependencies are fully met.
To install and use site-local version of Drush and Drupal Console, do the following:
Drush 8+ can hand-off the Drush command to a site-local installation. It will detect this if invoked from inside a composer/drupal installation. To install a global version:
composer global require drush/drush:~8.0
This installs the latest version of Drush 8 into ~/.composer/vender/bin. You need to make sure your Shell has this dir in its $PATH to use it.
Now install a site-local Drush for each project as needed:
- D8 does this automatically if you use a composer template. Look in the "require" section for "drush/drush": "~8.0".
- D7 and D6 are compatible with the global drush 8. Optionally you can install a different local version in the root of your project:
composer init --require=drush/drush:~7.0 -n composer install
This installs the latest version of Drush 7 in <site>/vendor/bin.
Now all your projects switch to use the compatible Drush version when invoked from within the project dir.
Drupal Console can hand-off the Console command to a site-local installation. It will detect this if invoked from inside a composer/drupal installation. You don't need to install a global version. Instead install the Drupal Console Launcher globally:
curl https://drupalconsole.com/installer -L -o drupal.phar
mv drupal.phar /usr/local/bin/drupal
chmod +x /usr/local/bin/drupal
This installs the latest version of Drupal Console Launcher into /usr/local/bin.
Now install a site-local Drupal Console for each project as needed. D8 does this automatically if you use a composer template. Look in the "require" section for "drupal/console": "~1.0".
Now all your projects switch to use the compatible Drupal Console version when invoked from within the project dir.
Another tip when working with Drupal Console in PhpStorm: Change the colour scheme so Drupal Console error messages become legible: alter the PhpStorm setting for the console color ANSI: red. This is the colour Drupal Console uses as background for it's errors.
about the author
Finne Fortuin is Drupal development and deployment configuration expert.