Project

General

Profile

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

Jack Aponte, 03/29/2016 01:08 AM

1 1 Jack Aponte
h1. Installing Drush for working with Drupal 6-8 and Backdrop
2
3 3 Jack Aponte
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":https://github.com/drush-ops/drush/issues/1581 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":https://github.com/backdrop-contrib/drush installed with Drush 7, "Drush stops working with Drupal 7.":https://github.com/backdrop-contrib/drush/issues/9
4 1 Jack Aponte
5
Therefore, when we're working with Drupal 6 or 7, we want to use Drush 7; when we're using Drupal 8 or Backdrop, we want to use Drush 8.
6
7
h2. Install Drush 7 and Drush 8 for all users
8
9
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/.
10
11
To install Drush 7, run the following commands as root or using @sudo@.
12
13
<pre>
14
git clone https://github.com/drush-ops/drush.git -b 7.2.0 /usr/local/src/drush7
15
cd /usr/local/src/drush7
16
composer install
17
ln -s /usr/local/src/drush7/drush /usr/bin/drush7
18
</pre>
19
20
Replace "7.2.0" with the tag of the most recent stable 7.x release (see https://github.com/drush-ops/drush/releases).
21
22
Then install Drush 8, again running these commands as root or using @sudo@.
23
24
<pre>
25
git clone https://github.com/drush-ops/drush.git -b 8.0.5 /usr/local/src/drush8
26
cd /usr/local/src/drush8
27
composer install
28
ln -s /usr/local/src/drush8/drush /usr/bin/drush8
29
</pre>
30
31
Replace "8.0.5" with the tag of the most recent stable 8.x release (see https://github.com/drush-ops/drush/releases)
32
33
You can now run @drush7@ or @drush8@ to use each specific version of Drush.
34
35
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.
36
37
<pre>
38
ln -s /usr/local/src/drush8/drush /usr/bin/drushbd
39
</pre>
40
41
*EXTRA TIP:* To update version of Drush installed as outlined above, run the following commands within the @/usr/local/src/<drush-version>@ directory:
42
43
<pre>
44
git pull origin master
45
git checkout tags/7.2.0 -b 7.2.0
46
composer install
47
</pre>
48
49
Replace "7.2.0" with the most recent stable release of the Drush version you're updating.
50
51 4 Jack Aponte
h2. Install Backdrop Drush commands.
52
53
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.
54
55
Assuming that Drush 8 is installed in @/usr/local/src/drush8@, as specified above:
56
57
<pre>
58
git clone https://github.com/backdrop-contrib/drush.git /usr/local/src/drush8/commands/backdrop
59
</pre>
60
61 1 Jack Aponte
h2. Create script to automatically switch Drush versions based on git configuration setting
62
63
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.
64
65
The script, which lives at @/usr/bin/drush@ and is therefore called whenever someone runs the @drush@ command:
66
67
<pre>
68
#!/bin/bash
69
version=$(git config --get drush.version)
70
if [ "$version" = '8' ];
71
then
72
    drush8 "$@"
73
elif [ "$version" = 'backdrop' ];
74
then
75
    drushbd "$@"
76
else
77
    drush7 "$@"
78
fi
79
</pre>
80
81 2 Jack Aponte
h2. Set drush.version git variable on a per-project basis
82 1 Jack Aponte
83
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:
84
85
<pre>
86
$ drush --version
87
 Drush Version   :  7.2.0
88
$ git config drush.version 8
89
$ drush --version
90
 Drush Version   :  8.0.5
91
</pre>
92
93
For Backdrop, run @git config drush.version backdrop@.
94
95 2 Jack Aponte
h2. Update drush remote aliases to use correct Drush scripts
96 1 Jack Aponte
97
If you've got aliases set up for remote sites, 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>.
98
99
An example @aliases.drushrc.php@ file with <code>%drush-script</code> specified:
100
101
<pre>
102
$aliases['drupal8'] = array(
103
  'remote-host' => 'fake-dev-server.palantetech.coop',
104
  'remote-user' => 'jack',
105
  'root' => '/var/www/dev/drupal8',
106
  'uri' => 'drupal8.palantetech.coop',
107
  'path-aliases' => array(
108
    '%drush-script' => '/usr/bin/drush8',
109
  )
110
);
111
$aliases['backdrop'] = array(
112
  'remote-host' => 'fake-dev-server.palantetech.coop',
113
  'remote-user' => 'jack',
114
  'root' => '/var/www/dev/backdrop',
115
  'uri' => 'backdrop.palantetech.coop',
116
  'path-aliases' => array(
117
    '%drush-script' => '/usr/bin/drushbd',
118
  )
119
);
120
</pre>
Go to top