Project

General

Profile

Installing Drush for working with Drupal 6-8 and Backdrop » History » Version 11

Jack Aponte, 04/01/2016 06:43 PM

1 1 Jack Aponte
h1. Installing Drush for working with Drupal 6-8 and Backdrop
2
3 9 Jack Aponte
Palante has a few reasons to run different versions of Drush:
4
5
* We're currently supporting or building Drupal 6, 7, 8 _and_ Backdrop sites.
6
* We've fallen victim to the "weird gotcha where Drush destroys your git repo and other non-Drupal files":https://github.com/drush-ops/drush/issues/1581 that seems to happen more often with Drush 8 than other versions.
7
* 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.
8 1 Jack Aponte
9 6 Jack Aponte
Below is a solution that allows us to use Drush 6, 7 and 8 in the same environment.
10 1 Jack Aponte
11 6 Jack Aponte
h2. Install Drush 6, 7 and 8 for all users
12 1 Jack Aponte
13 11 Jack Aponte
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":http://docs.drush.org/en/7.x/install/, adapted for different versions of Drush.
14 1 Jack Aponte
15 8 Jack Aponte
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@.
16
17
<pre>
18
git clone https://github.com/drush-ops/drush.git -b 6.6.0 /usr/local/src/drush6
19
cd /usr/local/src/drush6
20
composer install
21
ln -s /usr/local/src/drush6/drush /usr/bin/drush6
22
</pre>
23
24 1 Jack Aponte
To install Drush 7, run the following commands as root or using @sudo@.
25
26
<pre>
27
git clone https://github.com/drush-ops/drush.git -b 7.2.0 /usr/local/src/drush7
28
cd /usr/local/src/drush7
29
composer install
30
ln -s /usr/local/src/drush7/drush /usr/bin/drush7
31
</pre>
32
33
Replace "7.2.0" with the tag of the most recent stable 7.x release (see https://github.com/drush-ops/drush/releases).
34
35
Then install Drush 8, again running these commands as root or using @sudo@.
36
37 6 Jack Aponte
<pre>
38
git clone https://github.com/drush-ops/drush.git -b 8.0.5 /usr/local/src/drush8
39 1 Jack Aponte
cd /usr/local/src/drush8
40 6 Jack Aponte
composer install
41
ln -s /usr/local/src/drush8/drush /usr/bin/drush8
42
</pre>
43 1 Jack Aponte
44
Replace "8.0.5" with the tag of the most recent stable 8.x release (see https://github.com/drush-ops/drush/releases)
45
46
You can now use the @drush6@, @drush7@ or @drush8@ commands to run each specific version of Drush.
47
48
*EXTRA TIP:* To update version of Drush installed as outlined above, run the following commands within the @/usr/local/src/<drush-version>@ directory:
49
50
<pre>
51
git pull origin master
52 8 Jack Aponte
git checkout tags/<new version> -b <new version>
53 1 Jack Aponte
composer install
54
</pre>
55
56 8 Jack Aponte
Replace @<new version>@ with the most recent stable release of the Drush version you're updating.
57 1 Jack Aponte
58 5 Jack Aponte
h2. Install Backdrop Drush commands
59 4 Jack Aponte
60
In order for Drush to work with Backdrop, you must install the "Drush Backdrop commands":https://github.com/backdrop-contrib/drush within the Drush 8 installation itself.
61
62
Assuming that Drush 8 is installed in @/usr/local/src/drush8@, as specified above:
63
64
<pre>
65
git clone https://github.com/backdrop-contrib/drush.git /usr/local/src/drush8/commands/backdrop
66
</pre>
67 1 Jack Aponte
68
h2. Create script to automatically switch Drush versions based on git configuration setting
69
70
As per "this excellent guide from Marc van Gend of Triquanta":https://www.triquanta.nl/blog/automatically-switch-drush-versions-project, I've set up a script to let us switch between versions of Drush on a project-by-project basis using git configuration settings.
71
72
The script, which lives at @/usr/bin/drush@ and is therefore called whenever someone runs the @drush@ command:
73
74
<pre>
75
#!/bin/bash
76
version=$(git config --get drush.version)
77
if [ "$version" = '8' ];
78
then
79
    drush8 "$@"
80 6 Jack Aponte
elif [ "$version" = '6' ];
81
  then
82
  drush6 "$@"
83 1 Jack Aponte
else
84
    drush7 "$@"
85
fi
86 2 Jack Aponte
</pre>
87 1 Jack Aponte
88
h2. Set drush.version git variable on a per-project basis
89
90 8 Jack Aponte
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:
91 1 Jack Aponte
92
<pre>
93
$ drush --version
94
 Drush Version   :  7.2.0
95
$ git config drush.version 8
96
$ drush --version
97
 Drush Version   :  8.0.5
98
</pre>
99
100
h2. Update Drush remote site aliases to use correct Drush scripts
101
102
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":https://github.com/drush-ops/drush/blob/master/examples/example.aliases.drushrc.php file if you need help creating your @aliases.drushrc.php@ file or learning about <code>%drush-script</code>.
103 7 Jack Aponte
104 1 Jack Aponte
An example @aliases.drushrc.php@ file with <code>%drush-script</code> specified:
105
106
<pre>
107
$aliases['drupal8'] = array(
108
  'remote-host' => 'fake-dev-server.palantetech.coop',
109
  'remote-user' => 'jack',
110
  'root' => '/var/www/dev/drupal8',
111
  'uri' => 'drupal8.palantetech.coop',
112
  'path-aliases' => array(
113
    '%drush-script' => '/usr/bin/drush8',
114
  )
115
);
116 8 Jack Aponte
$aliases['drupal7'] = array(
117 1 Jack Aponte
  'remote-host' => 'fake-dev-server.palantetech.coop',
118
  'remote-user' => 'jack',
119 8 Jack Aponte
  'root' => '/var/www/dev/drupal7',
120
  'uri' => 'drupal7.palantetech.coop',
121 1 Jack Aponte
  'path-aliases' => array(
122 8 Jack Aponte
    '%drush-script' => '/usr/bin/drush7',
123 1 Jack Aponte
  )
124
);
125
</pre>
126 10 Jack Aponte
127
h2. Additional resources
128
129
* https://www.triquanta.nl/blog/automatically-switch-drush-versions-project
130
* https://www.lullabot.com/articles/switching-drush-versions
Go to top