1

I have installed Drupal 8.5 using composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --stability dev --no-interaction.

This command install many files. I found drush-files in the root and the file vendor/drush. It looks like Drush is available, but I have no idea how I can run drush. Trying command like "drush cr" was not successful. I get the following error.

-bash: drush: command not found.

I don't want to be able to use Drush from everywhere.

How can I use Drush only from my_site_name_dir?

  • Did you try cding into the docroot (or web) folder and running ../vendor/bin/drush ? If that works, whats missing is an alias. I am not familiar with Drupal-Composer but some scaffolders like Acquia BLT do that part for you automagically. Did you also try restarting terminal? – Kevin Apr 14 '18 at 16:22
  • @Kevin Yes I have tried with no success. But the alias was a good reference. I make one in my .bash_profile. And now it works for me. – lesley n. Apr 15 '18 at 8:42
3

Basically, you need to follow steps on http://docs.drush.org/en/master/install and get Drush installed globally. It's possible to invoke Drush installed within Composer context together with Drupal 8 indicating the exact path something like /path-to-website-home/vendor/bin/drush. However, if you want Drush available anywhere in the system then get Drush Launcher installed.

Here is direct quote from http://docs.drush.org/en/master/install:

Optional. To be able to call drush from anywhere, install the Drush Launcher. That is a small program which listens on your $PATH and hands control to a site-local Drush that is in the /vendor directory of your Composer project. If you skip this step, run Drush from Drupal root via ../vendor/bin/drush. In that case Drush's bash integration and custom prompt won't work.

You might also want to read How to get Drush to work with Composer and What is the right way of installing Drupal 8?

  • I thought this was no longer advised and instead you should use Drush 9 and install it as a project dependency? – Kevin Apr 14 '18 at 16:23
  • Drush 9 will work only with Drupal 8, but there could be Drupal 7 or 6 websites on the same server, so when you say I don't want to be able to use Drush from everywhere that means Drush work with all versions of Drupal and that's where Drush Launcher comes in to play as it automatically detects Drupal version of the current working directory and loads necessary Drush version environment. – AltaGrade Apr 14 '18 at 18:21
-1

I got it by myself. There is no need to install drush globally. The composer command
composer require drush/drush
install all the necessary files for using drush. To make Drush run you need an alias to this file in your .bash_profile (mac users). I only add in the .bash_profile alias drush='vendor/drush/drush/drush'
And Drush works!
And there is also no need to have trouble with different drupal versions, because composer install the version you need.

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.