Project

General

Profile

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

Jack Aponte, 07/08/2016 08:46 PM
Quick MFPL instructions

1 14 Jack Aponte
{{lastupdated_at}} by {{lastupdated_by}}
2
3 1 Jack Aponte
h1. Installing Drush for working with Drupal 6-8 and Backdrop
4
5 9 Jack Aponte
Palante has a few reasons to run different versions of Drush:
6
7
* We're currently supporting or building Drupal 6, 7, 8 _and_ Backdrop sites.
8
* 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.
9
* 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.
10 1 Jack Aponte
11 6 Jack Aponte
Below is a solution that allows us to use Drush 6, 7 and 8 in the same environment.
12 1 Jack Aponte
13 6 Jack Aponte
h2. Install Drush 6, 7 and 8 for all users
14 1 Jack Aponte
15 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.
16 1 Jack Aponte
17 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@.
18
19
<pre>
20
git clone https://github.com/drush-ops/drush.git -b 6.6.0 /usr/local/src/drush6
21
cd /usr/local/src/drush6
22 1 Jack Aponte
composer install
23
ln -s /usr/local/src/drush6/drush /usr/bin/drush6
24 16 Jack Aponte
</pre>
25
26
Quick adaptation for sites on May First/People Link (TODO: needs improvement!)
27
28
Primarily drawn from "this MFPL ticket.":https://support.mayfirst.org/ticket/11691#comment:3
29
30
First, install Composer following "these instructions":https://getcomposer.org/download/.
31
32
Then to install Drush:
33
34
<pre>
35
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
36
source ~/.bashrc
37
cd ~/web.warresisters.org/bin
38
php composer.phar global require drush/drush
39
which drush
40 8 Jack Aponte
</pre>
41
42 1 Jack Aponte
To install Drush 7, run the following commands as root or using @sudo@.
43
44
<pre>
45 13 Jon Goldberg
git clone https://github.com/drush-ops/drush.git -b 7.3.0 /usr/local/src/drush7
46 1 Jack Aponte
cd /usr/local/src/drush7
47
composer install
48
ln -s /usr/local/src/drush7/drush /usr/bin/drush7
49
</pre>
50
51 13 Jon Goldberg
Replace "7.3.0" with the tag of the most recent stable 7.x release (see https://github.com/drush-ops/drush/releases).
52 1 Jack Aponte
53
Then install Drush 8, again running these commands as root or using @sudo@.
54
55 6 Jack Aponte
<pre>
56
git clone https://github.com/drush-ops/drush.git -b 8.0.5 /usr/local/src/drush8
57 1 Jack Aponte
cd /usr/local/src/drush8
58 6 Jack Aponte
composer install
59
ln -s /usr/local/src/drush8/drush /usr/bin/drush8
60
</pre>
61 1 Jack Aponte
62
Replace "8.0.5" with the tag of the most recent stable 8.x release (see https://github.com/drush-ops/drush/releases)
63
64
You can now use the @drush6@, @drush7@ or @drush8@ commands to run each specific version of Drush.
65
66 12 Jack Aponte
*EXTRA TIP:* To update a Drush installation installed in this manner, run the following commands within the @/usr/local/src/<drush-version>@ directory:
67 1 Jack Aponte
68
<pre>
69
git pull origin master
70 8 Jack Aponte
git checkout tags/<new version> -b <new version>
71 1 Jack Aponte
composer install
72
</pre>
73
74 8 Jack Aponte
Replace @<new version>@ with the most recent stable release of the Drush version you're updating.
75 1 Jack Aponte
76 5 Jack Aponte
h2. Install Backdrop Drush commands
77 4 Jack Aponte
78
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.
79
80
Assuming that Drush 8 is installed in @/usr/local/src/drush8@, as specified above:
81
82
<pre>
83
git clone https://github.com/backdrop-contrib/drush.git /usr/local/src/drush8/commands/backdrop
84
</pre>
85 1 Jack Aponte
86
h2. Create script to automatically switch Drush versions based on git configuration setting
87
88
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.
89
90
The script, which lives at @/usr/bin/drush@ and is therefore called whenever someone runs the @drush@ command:
91
92
<pre>
93
#!/bin/bash
94
version=$(git config --get drush.version)
95
if [ "$version" = '8' ];
96
then
97
    drush8 "$@"
98 6 Jack Aponte
elif [ "$version" = '6' ];
99
  then
100
  drush6 "$@"
101 1 Jack Aponte
else
102
    drush7 "$@"
103
fi
104 2 Jack Aponte
</pre>
105 1 Jack Aponte
106
h2. Set drush.version git variable on a per-project basis
107
108 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:
109 1 Jack Aponte
110
<pre>
111
$ drush --version
112
 Drush Version   :  7.2.0
113
$ git config drush.version 8
114
$ drush --version
115
 Drush Version   :  8.0.5
116
</pre>
117
118
h2. Update Drush remote site aliases to use correct Drush scripts
119
120
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>.
121 7 Jack Aponte
122 1 Jack Aponte
An example @aliases.drushrc.php@ file with <code>%drush-script</code> specified:
123
124
<pre>
125
$aliases['drupal8'] = array(
126
  'remote-host' => 'fake-dev-server.palantetech.coop',
127
  'remote-user' => 'jack',
128
  'root' => '/var/www/dev/drupal8',
129
  'uri' => 'drupal8.palantetech.coop',
130
  'path-aliases' => array(
131
    '%drush-script' => '/usr/bin/drush8',
132
  )
133
);
134 8 Jack Aponte
$aliases['drupal7'] = array(
135 1 Jack Aponte
  'remote-host' => 'fake-dev-server.palantetech.coop',
136
  'remote-user' => 'jack',
137 8 Jack Aponte
  'root' => '/var/www/dev/drupal7',
138
  'uri' => 'drupal7.palantetech.coop',
139 1 Jack Aponte
  'path-aliases' => array(
140 8 Jack Aponte
    '%drush-script' => '/usr/bin/drush7',
141 1 Jack Aponte
  )
142
);
143
</pre>
144 10 Jack Aponte
145
h2. Additional resources
146
147
* https://www.triquanta.nl/blog/automatically-switch-drush-versions-project
148
* https://www.lullabot.com/articles/switching-drush-versions
Go to top