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