Project

General

Profile

Actions

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

« Previous | Revision 28/62 (diff) | Next »
Jack Aponte, 06/29/2017 05:58 PM
made note about problems running composer install as root


Updated over 7 years ago by Jack Aponte

Installing Drush for working with Drupal 6-8 and Backdrop

Palante has a few reasons to run different versions of Drush:

  • We're currently supporting or building Drupal 6, 7, 8 and Backdrop sites.
  • 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.
  • Some of our clients' servers don't support anything newer than Drush 6; if we run remote commands against those servers, like drush sql-sync, we need to use Drush 6 locally, too.

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, adapted for different versions of Drush.

TODO: Update the instructions below to indicate that running composer install as root is a security risk, give alternative approach.

Some of our clients' servers aren't capable of running anything newer than Drush 6. If you need to run commands like drush sql-sync against those servers from your local or dev environment, you'll need Drush 6 installed. Run the following commands as root or using sudo.

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

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

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

Replace "7.4.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.1.12 /usr/local/src/drush8
cd /usr/local/src/drush8
composer install
ln -s /usr/local/src/drush8/drush /usr/bin/drush8

Replace "8.1.12" (last updated in this documentation on 6/6/17) with the tag of the most recent stable 8.x release (see https://github.com/drush-ops/drush/releases)

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

EXTRA TIP: To update a Drush installation installed in this manner, run the following commands within the /usr/local/src/<drush-version> directory:

git pull origin master
git checkout tags/<new version> -b <new version>
composer install

Replace <new version> with the most recent stable release of the Drush version you're updating.

Install Drush on May First/People Link (MFPL) and other shared hosting environments

Primarily drawn from this MFPL ticket; thanks Ivan!

First, install Composer following these instructions.

Then to install Drush:

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
cd ~/<organization.org>/bin
php composer.phar global require drush/drush:7.4.0
which drush

Note that sometimes cgi-bin is present on MFPL sites instead of bin.

If using Drush aliases, you may need to specify the new Drush installation in the shared aliases.drushrc.php file or a local aliases file. Here's an example:

$aliases['organization'] = array(
  'remote-host' => 'organization.org',
  'remote-user' => 'organization',
  'root' => '/home/members/organization/sites/organization.org/web',
  'uri' => 'organization.org',
  'path-aliases' => array(
    '%drush-script' => '/home/members/organization/sites/organization.org/users/organization/.composer/vendor/bin/drush',
    '%dump-dir' => '~/drush-backups',
    '%files' => '/home/members/organization/sites/organization.org/web/sites/default/files',),
);

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" = '6' ];
  then
  drush6 "$@" 
else
    drush7 "$@" 
fi

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

In this configuration, Drush 7 is the default version of Drush. For the script above to automatically switch to a non-default version of Drush for a given project, 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

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['drupal7'] = array(
  'remote-host' => 'fake-dev-server.palantetech.coop',
  'remote-user' => 'jack',
  'root' => '/var/www/dev/drupal7',
  'uri' => 'drupal7.palantetech.coop',
  'path-aliases' => array(
    '%drush-script' => '/usr/bin/drush7',
  )
);

Additional resources

Updated by Jack Aponte over 7 years ago · 28 revisions

Also available in: PDF HTML TXT

Go to top