Skip to content
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 that global Drush 8 can detect Drush 12 in a local Drupal 10 installation #5741

Closed
gitressa opened this issue Aug 24, 2023 · 11 comments

Comments

@gitressa
Copy link
Contributor

Existing document

https://github.com/drush-ops/drush-launcher was recently archived. On the project page, it says:

Add ./vendor/bin to the front of your $PATH. This relative path works for any Drupal codebase on your system if you run commands from the project root. And it is harmless otherwise. Other options include direnv, fd, or the scripts drush-ops/drush-launcher#105.

What are you attempting to do
I have both a non-Composer Drupal 7 installations with a globally installed Drush 8, and a Composer-run Drupal 10 with local Drush 12 concurrently on the same server. These two Drush versions actually seem to work well together, even without Drush Launcher, as discovered by @gisle in which drush for Drupal 10.1.2 on debian 10. Drush 8 will detect that Drush 12 is available in a Drupal 10 installation. This is great news, and should be documented.

In what way is the existing documentation unclear or incomplete
Currently, it looks like you might need to replace drush-launcher with some advanced configuration, if you want to run Drush 8 and Drush 12 on the same server, but this doesn't seem necessary.

What should the documentation say instead?
We could update the introduction, by adding a sentence that the above set up is possible, and works without any extra efforts. Suggestion:

Add ./vendor/bin to the front of your $PATH. This relative path works for any Drupal codebase on your system if you run commands from the project root. And it is harmless otherwise.
You can run a non-Composer Drupal 7 installations with a globally installed Drush 8, and a Composer-run Drupal 10 with local Drush 12 concurrently on the same server. Drush will automagically detect which Drush version to use, according to from where the command is run.
Other options include direnv, fd, or the scripts drush-ops/drush-launcher#105.

This is just a rough draft, but let's try to figure out a good wording, and document this great feature.

@fenstrat
Copy link

fenstrat commented Sep 1, 2023

Confirming this works as described. Would be great to see it documented.

It seems to depends on Drush 12 being available at /d10/bin/drush (where d10 is your Drupal 10 root). Then the global Drush 8 install (e.g. in /usr/local/bin/drush) will automatically pass off to the Drush 12 version if drush is called anywhere under d10.

@gitressa
Copy link
Contributor Author

gitressa commented Sep 1, 2023

Thanks for confirming @fenstrat.

And yes, /drupal10/vendor/bin/drush is where a Drush 12 installed in Drupal 10 with Composer will get placed with composer require drush/drush which is the standard recommended method of installing Drush in Drupal 10, just as modules will get downloaded to /drupal10/web/modules/contrib, themes in /drupal10/web/themes/contrib etc.

About paths and discoverability, I usually install Drush 8 (for Drupal 7) in ~/.local/bin where my Composer file also lives. This makes it easier to install, since root permissions are not needed:

Check if path ~/.local/bin is present with echo $PATH. If not, create the folder(s) and register them. Add in .bashrc file:

export PATH="/home/webuser/.local/bin/:$PATH"

Create the folders, source them and check:

$ mkdir -p ~/.local/bin
$ source .bashrc 
$ echo $PATH
/home/webuser/.local/bin/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin

Install Drush 8.4.12 as ordinary user:

$ cd ~/.local/bin/
$ wget https://github.com/drush-ops/drush/releases/download/8.4.12/drush.phar -O drush
$ chmod +x drush

@gitressa
Copy link
Contributor Author

gitressa commented Sep 2, 2023

I am no sure if it is related, but I just got a permission error on another server, from inside the Drupal 10 installation:

$ drush st
PHP Warning:  pcntl_exec(): Error has occurred: (errno 13) Permission denied in phar:///home/webuser/.local/bin/drush/includes/startup.inc on line 422
Error has occurred executing the Drush script found at /var/www/website/public_html/vendor/bin/drush
(errno 13) Permission denied

I also got this:

$ ./vendor/bin/drush st
-bash: ./vendor/bin/drush: Permission denied

I had to run this for it to work:
$ chmod +x vendor/bin/drush

After that drush st worked fine.

UPDATE: It was unrelated. I found Errno 13: Permission Denied and ran these commands:

rm -rf vendor
composer install

Now, permissions in /vendor and files and folders below are relaxed from r-xr----- (from memory) to rwxr-xr-x.

The real problem was that I was running the commands in Securing file permissions and ownership not from the relocated web root (/web) but in the root of the Drupal installation, in the folder with composer.json, /vendor, etc. Face palm.

@weitzman
Copy link
Member

I do appreciate the desire to inform. This issue lives on for anyone who needs it. However a global install of drush really isn't supported or encouraged.

@gitressa
Copy link
Contributor Author

But global Drush is the recommended method of installing Drush 8 ...

Install/Upgrade a global Drush

# Browse to https://github.com/drush-ops/drush/releases and download the drush.phar attached to the latest 8.x release.

# Test your install.
php drush.phar core-status

# Rename to drush instead of php drush.phar. Destination can be anywhere on $PATH.
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush
[...]

If this is not the recommended method to install Drush 8 for a non-Composer Drupal 7 installation, should we instead place a separate drush.phar file in the root of each project? I would guess that a lot (if not most) Drupal 7 sites are not Composer-based ...

@weitzman
Copy link
Member

The user is trying to use Drupal 10 and Drush 12 in the scenario described. A global Drush is not needed nor supported in this scenario. Call vendor/bin/drush directly. The Alternatives section may also be helpful - https://github.com/drush-ops/drush-launcher#alternatives-now-that-this-project-is-archived.

@gitressa
Copy link
Contributor Author

Thanks, but the scenario is having both a Drupal7/Drush8 (non-Composer) as well as a Drupal10/Drush12 (Composer) running on the same server:

I have both a non-Composer Drupal 7 installations with a globally installed Drush 8, and a Composer-run Drupal 10 with local Drush 12 concurrently on the same server.

Drupal10/Drush12 is locally installed as recommended, the global installation I am referring to is Drupal7/Drush8.

So my question is, if a global installation for Drush 8 is also not recommended for this set up? If not, what is the recommended method of installing Drush 8 for Drupal 7, non-Composer based?

@weitzman
Copy link
Member

@greg-1-anderson is the drush8 person, but AFAIK the global drush8 is your only option for a non-composer d7 site. The fact that the same Drush can call into a Drush12 elsewhere on the system is lucky, and unsupported.

@gitressa
Copy link
Contributor Author

Thanks for clearing that up @weitzman. I very much appreciate you and @greg-1-anderson's work with maintaining Drush. And sure, let's not document it, but let it stay here, for other people to find.

Though, having Drupal10/Drush12 locally installed combined with global Drupal7/Drush8 scenario is not rare, so there is a risk that "something" unforeseen might happen in the future, unless it is taken into account for code updates between now and January 2025, when Drush 8 is EOL ...

@augustofagioli
Copy link

Find the path to the correct drush by an anchor positioned exactly at the base of the drupal instance

Useful when your need drush for Drupal 10.2 and older

   #!/bin/bash
   slashes=${PWD//[^\/]/}

   #create this at drupal root instance 
   anchor="anchor.drush"

   directory="${PWD}/"
   for (( n=${#slashes}; n>0; --n ))
   do
    trythis="${directory}${anchor}"
     if  [ -e "$trythis" ]
      then
        top=$directory
        vendor="vendor/drush/drush"
        $top$vendor/drush "$@"
      fi
      directory+="../"  
    done

@gitressa
Copy link
Contributor Author

gitressa commented Dec 13, 2024

UPDATE: I tried removing the global Drush and it's still slow, so please disregard :)

==========

Recently, it seems like the Global Drush 8 is called, even when using vendor/bin/drush in a Drupal 10 site with Drush 13. The command hangs for more than 2 minutes, before completing.

Scenario:

  • Local Drush 13 instances for each Drupal 10 site (Composer)
  • Global Drush 8 for Drupal 7 sites (non-Composer)

drush

Using simply drush, it looks like the global Drush is used, with the "Box Requirements Checker":

$ time drush st -vvv

Box Requirements Checker
========================

> Using PHP 8.3.14
> PHP is using the following php.ini file:
  /etc/php/8.3/cli/php.ini

> Checking Box requirements:
  ✔ The application requires a version matching ">=5.4.5".
  ✔ The application requires the extension "zlib".
  ✔ The package "jakub-onderka/php-console-highlighter" requires the extension "tokenizer".
  ✔ The package "nikic/php-parser" requires the extension "tokenizer".
  ✔ The package "psy/psysh" requires the extension "tokenizer".
  ✔ The package "psy/psysh" requires the extension "json".
  ✔ The package "webflo/drupal-finder" requires the extension "json".
                                                                                                                         
 [OK] Your system is ready to run the application.                                                                     
                                                                                                                       
 [preflight] Config paths: /var/www/html/example.com/public_html/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /var/www/html/example.com/public_html/web/drush/sites,/var/www/html/example.com/public_html/drush/sites
 [preflight] Commandfile search paths: /var/www/html/example.com/public_html/vendor/drush/drush/src
 [info] Starting bootstrap to max [0.71 sec, 9.67 MB]
 [...]
 [info] Executing: mysql --defaults-file=/tmp/drush_WARLLV --database=example_com --host=localhost --port=3306 --silent -A < /tmp/drush_jQ9DlV [1.09 sec, 33.15 MB]
Drupal version   : 10.3.10                                                               
Site URI         : http://default                                                        
DB driver        : mysql                                                                 
DB hostname      : localhost                                                             
DB port          : 3306                                                                  
Database         : Connected                                                             
Drupal bootstrap : Successful                                                            
PHP binary       : /usr/bin/php8.3                                                       
PHP config       : /etc/php/8.3/cli/php.ini                                              
PHP OS           : Linux                                                                 
PHP version      : 8.3.14                                                                
Drush script     : /var/www/html/example.com/public_html/vendor/bin/drush.php         
Drush version    : 13.3.3.0                                                              
Drush temp       : /tmp                                                                  
Drush configs    : /var/www/html/example.com/public_html/vendor/drush/drush/drush.yml 
Install profile  : minimal                                                               
Drupal root      : /var/www/html/example.com/public_html/web                          
Site path        : sites/default                                                         
Files, Public    : sites/default/files                                                   
Files, Temp      : /tmp                                                                  

real  2m14,514s
user  0m0,294s
sys 0m0,196s

vendor/bin/drush

The "Box Requirements Checker" is not shown ... but it still takes +2 minutes.

$ time vendor/bin/drush st -vvv
 [preflight] Config paths: /var/www/html/example.com/public_html/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /var/www/html/example.com/public_html/web/drush/sites,/var/www/html/example.com/public_html/drush/sites
 [preflight] Commandfile search paths: /var/www/html/example.com/public_html/vendor/drush/drush/src
 [info] Starting bootstrap to max [1.12 sec, 9.67 MB]
 [...]
 [info] Executing: mysql --defaults-file=/tmp/drush_lKgzG7 --database=example_com --host=localhost --port=3306 --silent -A < /tmp/drush_72HU6I [1.45 sec, 33.14 MB]
Drupal version   : 10.3.10                                                               
Site URI         : http://default                                                        
DB driver        : mysql                                                                 
DB hostname      : localhost                                                             
DB port          : 3306                                                                  
Database         : Connected                                                             
Drupal bootstrap : Successful                                                            
PHP binary       : /usr/bin/php8.3                                                       
PHP config       : /etc/php/8.3/cli/php.ini                                              
PHP OS           : Linux                                                                 
PHP version      : 8.3.14                                                                
Drush script     : /var/www/html/example.com/public_html/vendor/bin/drush.php         
Drush version    : 13.3.3.0                                                              
Drush temp       : /tmp                                                                  
Drush configs    : /var/www/html/example.com/public_html/vendor/drush/drush/drush.yml 
Install profile  : minimal                                                               
Drupal root      : /var/www/html/example.com/public_html/web                          
Site path        : sites/default                                                         
Files, Public    : sites/default/files                                                   
Files, Temp      : /tmp                                                                  

real  2m13,826s
user  0m0,257s
sys 0m0,166s

Is there a method, to have a Global Drush 8 co-exist peacefully with local Drush 13 instances?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants