5

On Ubuntu 14.04 I try to establish Drush through Composer.

I added PATH="~/.composer/vendor/bin:$PATH to either .bashrc or .bash_profile on a server.

Drush is invoked properly on the server.

But it does not properly for remotely: ssh myalias 'drush' bash: drush: command not found

I checked echo $PATH for both the webserver and remotely and I saw:

  • on the webserver: /home/<MY_USER>/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  • on the remote call: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Why there is a difference (there is not /home/<MY_USER>/.composer/vendor/bin)? How to add the correct path for remotely callbacks?

Artu
  • 63
  • Which machine is it invoked properly on? ("the server"? is that the same "the webserver"?) Which machine you open the SSH connection from? And to which machine? Call them by name, show the commands you run. And to which machines' .bashrc you added the PATH assignment? What do you mean with a "callback"? – ilkkachu Mar 13 '17 at 21:07
  • did you source the .bashrc or .bash_profile that you changed? – VaTo Mar 13 '17 at 22:11

3 Answers3

4

I'm going to make some assumptions here:

  • drush is installed within ~/.composer/vendor/bin
  • myalias is the name of the remote host on which you have drush
  • the webserver you mention is actually the same as myalias in your example command

When you log in interactively with bash as your shell, the bash startup script .bash_profile is executed. If you set your PATH here all is well and good, and you can find drush directly.

When you run something non-interactively such as ssh remotehost id, there is no login shell so .bash_profile is not run. However, since your shell is bash the session script .bashrc is executed. I suspect you don't set your PATH there, so drush cannot be found.

There are several options open to you. Here are four suggestions

  1. Make .bashrc call .bash_profile if it's not previously been called by this shell (my preference)
  2. Add a duplicate PATH=... line in .bashrc (easy)
  3. Move the environment settings out of .bash_profile and .bashrc into a common file that's sourced by .bash_profile and .bashrc (more elegant)
  4. Install drush in a system location (such as /usr/local/bin or somewhere under /opt) and ensure that this directory is included in the system-wide PATH settings (harder)
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
0
PATH="~/.composer/vendor/bin:$PATH" ssh myalias 'drush'

will provide for the modified PATH to ssh and any utilities that it invokes.

0

One other option (seen on the documentation here: https://www.drush.org/latest/site-aliases/)

Is to add the path to the drush script or drush launcher.

In your drush site alias file (often self.site.yml) add the following:

paths:
    drush-script: '/path/to/drush'

This will run the command using the drush script that doesn't necessarily have to be on the PATH variable.