-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to most easily make vendor/bin/drush
available as drush
#5828
Comments
It looks like better documentation is the best way forward, so adding some alternatives in the issue summary under "Possible solutions". Alias vs. But maybe there are good reasons to use |
Drush will sometimes call itself via If you use an alias, perhaps it could find the |
Thanks for clarifying @greg-1-anderson, that's an important piece of the puzzle. While updating the I'll move using an alias out of the possible solutions, and add your explanation why it's probably not a great idea. I suppose the
This raises another question for me: Is it actually required to add the Drush folder to |
drush
out of the box (not vendor/bin/drush
)vendor/bin/drush
available as drush
My thought was to use a function, and add Drush to the
Untested, but should work in concept. |
Here's a git free function, could be useful on production servers where git could not be available : drush() {
cur_path=$(pwd)
while [[ "$cur_path" != "" && ! -e "$cur_path/vendor/bin/drush" ]]; do
cur_path="${cur_path%/*}"
done
if [ -e "$cur_path/vendor/bin/drush" ]; then
eval "$cur_path/vendor/bin/drush $@"
else
echo "Could not found drush, maybe your not in a drupal folder or drush is not installed. See https://www.drupal.org/docs/develop/development-tools/drush"
fi
}
|
Thanks @greg-1-anderson! though your suggestion is using the Git function, not alias ... Also, do you know the answer to this question?
And thanks @obriat! That seems to work well. Perhaps you can briefly describe how it works? Mostly this bit: |
Hi, Here's the explanation: https://stackoverflow.com/questions/10535985/how-to-remove-filename-prefix-with-a-posix-shell/25536935#25536935 But I don't know how to add the Drush folder to |
@gitressa: As I mentioned in #5828 (comment), it is actually necessary to add Drush to the PATH. Sorry for being indistinct about @obriat: See #5828 (comment) for an example of adding Drush to the PATH. I haven't tried this function, but it might work. |
@greg-1-anderson I'm afraid that your proposition will add the drush path to the main $PATH each time it is executed and it could be worst if you have several projet on the same machine. Here's a proposition that should leave the $PATH untouched (but I'm not a shell expert so there should be room for improvement): drush() {
PROJECT_PATH=$(pwd)
while [[ "$PROJECT_PATH" != "" && ! -e "$PROJECT_PATH/vendor/bin/drush" ]]; do
PROJECT_PATH="${PROJECT_PATH%/*}"
done
if [ -e "$PROJECT_PATH/vendor/bin/drush" ]; then
SAVE_PATH=$PATH
PATH="$PROJECT_PATH/vendor/bin/drush:$PATH"
$PROJECT_PATH/vendor/bin/drush $@
PATH="$SAVE_PATH"
else
echo "Could not found drush, maybe your not in a drupal folder or drush is not installed. See https://www.drupal.org/docs/develop/development-tools/drush"
fi
} BONUS: |
Thanks for confirming that it's always necessary to add Drush to the PATH @greg-1-anderson. And thanks for experimenting with functions @obriat :) Since development environments such as DDEV and Lando offer It then follows that the documentation is mostly needed for configuring servers, where in my opinion, there is for the most situations no need to work from anything else than the root of the project, to run This is pretty much what is already documented on https://www.drush.org/latest/install/ under "2. Execution". I originally thought that maybe an alternative (and simple?) solution would be possible, which could be added to a "How to run simply drush"-documentation page -- but it doesn't seem like it, so far ... |
@obriat You are correct; however, you can fix that problem by adding parenthesis to my original suggestion:
I thought that the |
@gitressa Outside from "containered" dev tools, I've seen a lot of servers where more than one drupal site are running. @greg-1-anderson thanks for the tip, here's my new version (much longer but without git dependency): drush() {
(
PROJECT_PATH=$(pwd)
while [[ "$PROJECT_PATH" != "" && ! -e "$PROJECT_PATH/vendor/bin/drush" ]]; do
PROJECT_PATH="${PROJECT_PATH%/*}"
done
if [ -e "$PROJECT_PATH/vendor/bin/drush" ]; then
PATH="$PROJECT_PATH/vendor/bin/drush:$PATH" $PROJECT_PATH/vendor/bin/drush $@
else
echo "Could not found drush, maybe your not in a drupal folder or drush is not installed. See https://www.drupal.org/docs/develop/development-tools/drush"
fi
)
} |
Sure @obriat, but if you're always running commands from the project root, I just can't see why it's needed ... Maybe you can expand with some more context, and clarify this? |
Here's my really short version that makes
Works only at the project root if you don't have |
Just posting some (random) solutions that are worked on:
I think whatever solution we land on, it should be maintained here under "drush-ops". I think we should have something ready instead of too many options in the install instructions. |
@gitressa As I said, as a sysadmin I had to do some tasks on random subfolders or files (cache settings,…) and run drush (cr mostly). So in this case it could be useful to have a command that does not depend on a specific location. It’s this kind of “install and forget” setup that could bring a bit of magic that will make drush more easy to use, specially for people who are not Drupal specialists. |
I created dasginganinja/drush-launcher for a system-level There was a strong need for something in my $PATH. I didn't want a bunch of dependencies. We don't have git directories on production either. I wasn't a fan of the bash based profile solutions either. And, we have multiple installations on our systems. We like running Drush contextually, too. I'm open to PRs and want to help push this issue further. I personally feel there is still a space for the drush launcher. If it was maintained by drush-ops, then that'd be best for the community. 💯 |
When Drush calls itself via For example on a shared webhosting when I have different PHP versions available (and eventually two sites using different PHP versions, like production 8.2 and test 8.3) I must call Drush via
Of course using $PATH would work to determine the correct locations for PHP and Drush binaries. But how can the Parameter |
Both of those needs (PATH and custom php.ini) are mentioned briefly in the Note at https://www.drush.org/13.x/install/ |
Is your feature request related to a problem? Please describe.
The vast majority of Drupal sites use Drush on a Linux server. After installing Drush, you need to manually add it to the
$PATH
, or else you need to usevendor/bin/drush
, which is not ideal.Describe the solution you'd like
After installing Drush, it would be awesome if you could use the command
drush
, without any extra steps, but this is not possible, since the Drush folder needs to be added to the$PATH
manually. But we could look for alternative solutions, or expand the documentation.Additional context
drupal.org issue: https://www.drupal.org/project/ideas/issues/3405516
Possible solutions
Add in a Bash shell script file such as
~/.bashrc
, andsource
it to take effect.Using
$PATH
Add Drush folder to
$PATH
(reset withsource /etc/profile
)PATH=$PATH:./vendor/bin
If there's only one Drupal installation on the system, you can add the absolute path to the Drush folder, and now call
drush
from anywhere.PATH=$PATH:/path/to/project/vendor/bin
Function with Git
Use Git with a function, to allow running
drush
inside sub-folders, shared by chx. May only work with absolute Drush path registered in$PATH
(remove withunset -f drush
).Not recommended (
alias
)alias drush='vendor/bin/drush'
: This may seem like a simple and good solution, but Drush will sometimes call itself viaexec
. When it does this, Drush expects thatdrush
will be in the$PATH
. If you use an alias, this redispatch might not work correctly.The text was updated successfully, but these errors were encountered: