Project

General

Profile

Actions

Installing Drush for working with Drupal 6-8 and Backdrop » History » Revision 7

« Previous | Revision 7/62 (diff) | Next »
Jack Aponte, 03/29/2016 09:33 PM
improved section on aliases


Installing Drush for working with Drupal 6-8 and Backdrop

Because Palante is still supporting a number of Drupal 6 sites, and we've fallen victim to the weird gotcha where Drush destroys your git repo and other non-Drupal files that seems to happen more often with Drush 8 than other versions, we've decided to stick with Drush 7 as the default version in use at Palante. But since we are beginning to build Drupal 8 sites, we also need Drush 8 installed; Drush 8 is also better for Backdrop, which we're also working with, because with the Backdrop Drush commands installed with Drush 7, Drush stops working with Drupal 7. Finally, because we're interacting with some remote servers that can't support versions of Drush above 6, we also need to be able to use Drush 6 on occasion.

Below is a solution that allows us to use Drush 6, 7 and 8 in the same environment.

Install Drush 6, 7 and 8 for all users

I've followed the "To install for all users on the server" instructions under "Composer - One Drush for all Projects" in the Drush 7 installation documentation:.

To install Drush 7, run the following commands as root or using sudo.

git clone https://github.com/drush-ops/drush.git -b 7.2.0 /usr/local/src/drush7
cd /usr/local/src/drush7
composer install
ln -s /usr/local/src/drush7/drush /usr/bin/drush7

Replace "7.2.0" with the tag of the most recent stable 7.x release (see https://github.com/drush-ops/drush/releases).

Then install Drush 8, again running these commands as root or using sudo.

git clone https://github.com/drush-ops/drush.git -b 8.0.5 /usr/local/src/drush8
cd /usr/local/src/drush8
composer install
ln -s /usr/local/src/drush8/drush /usr/bin/drush8

Replace "8.0.5" with the tag of the most recent stable 8.x release (see https://github.com/drush-ops/drush/releases)

If you also need to work with Drush 6--for example, when you need to run commands like drush sql-sync against remote servers that can't run Drush 7 or later--you can install it in the same manner.

git clone https://github.com/drush-ops/drush.git -b 6.6.0 /usr/local/src/drush6
cd /usr/local/src/drush6
composer install
ln -s /usr/local/src/drush6/drush /usr/bin/drush6

You can now use the drush6, drush7 or drush8 commands to run each specific version of Drush.

Because I currently want to use Drush 8 when working with Backdrop, I'll also create a drushbd alias pointing to Drush 8; later, if Backdrop needs to use a different version of Drush, I can change where the drushbd alias points and continue to use that command.

ln -s /usr/local/src/drush8/drush /usr/bin/drushbd

EXTRA TIP: To update version of Drush installed as outlined above, run the following commands within the /usr/local/src/<drush-version> directory:

git pull origin master
git checkout tags/7.2.0 -b 7.2.0
composer install

Replace "7.2.0" with the most recent stable release of the Drush version you're updating.

Install Backdrop Drush commands

In order for Drush to work with Backdrop, you must install the Drush Backdrop commands within the Drush 8 installation itself.

Assuming that Drush 8 is installed in /usr/local/src/drush8, as specified above:

git clone https://github.com/backdrop-contrib/drush.git /usr/local/src/drush8/commands/backdrop

Create script to automatically switch Drush versions based on git configuration setting

As per this excellent guide from Marc van Gend of Triquanta, I've set up a script to let us switch between versions of Drush on a project-by-project basis using git configuration settings.

The script, which lives at /usr/bin/drush and is therefore called whenever someone runs the drush command:

#!/bin/bash
version=$(git config --get drush.version)
if [ "$version" = '8' ];
then
    drush8 "$@" 
elif [ "$version" = 'backdrop' ];
then
    drushbd "$@" 
elif [ "$version" = '6' ];
  then
  drush6 "$@" 
else
    drush7 "$@" 
fi

Set drush.version git variable on a per-project basis

For the script to automatically switch to the right version of Drush when working with Drupal 8 or Backdrop, set the drush.version value in the git repo for the project by running git config drush.version <version>. For example:

$ drush --version
 Drush Version   :  7.2.0
$ git config drush.version 8
$ drush --version
 Drush Version   :  8.0.5

For Backdrop, run git config drush.version backdrop.

Update Drush remote site aliases to use correct Drush scripts

If you've got Drush site aliases set up for remote sites on servers where multiple versions of Drush are available, update your aliases.drushrc.php file to include the specific drush script that should be used on the remote site. See the example.aliases.drushrc.php file if you need help creating your aliases.drushrc.php file or learning about %drush-script.

An example aliases.drushrc.php file with %drush-script specified:

$aliases['drupal8'] = array(
  'remote-host' => 'fake-dev-server.palantetech.coop',
  'remote-user' => 'jack',
  'root' => '/var/www/dev/drupal8',
  'uri' => 'drupal8.palantetech.coop',
  'path-aliases' => array(
    '%drush-script' => '/usr/bin/drush8',
  )
);
$aliases['backdrop'] = array(
  'remote-host' => 'fake-dev-server.palantetech.coop',
  'remote-user' => 'jack',
  'root' => '/var/www/dev/backdrop',
  'uri' => 'backdrop.palantetech.coop',
  'path-aliases' => array(
    '%drush-script' => '/usr/bin/drushbd',
  )
);

Updated by Jack Aponte almost 8 years ago · 7 revisions

Also available in: PDF HTML TXT

Go to top