… don’t know what drupal and drush are? Then this post is probably not for you…

Let’s face it – drush is a bitch to install. But we want it. So we have to.

Even though there appears to be extensive info on the topic on drush’s website, installing it may still be a daunting task.

Particularly – if you don’t run the latest version of php.

Why? Because the “extensive” installation instructions mostly deal with the default installation method which installs the latest version of drush.
…Which means – you’re using drupal 8 (but not all of us do!)…
…Which means – you’re using you have the latest php version installed (not all of us do!)
…Which means – you’re using the latest “composer” manager (again… not always the case)

SO… What are the ‘Les Miserables’ of us (who for one reason or another do not have the luxury of upgrading their setup to the latest and greatest drupal/php/composer!) to do?

1. To install drush you need composer (https://getcomposer.org/doc/00-intro.md). And composer needs php version 5.3.2 or higher to run. So if your php is lower than that and you can not upgrade it then you’re even more screwed. Your option (since you can not use composer to install drush) is to go to the drush git repository on github (https://github.com/drush-ops/drush) and find a version which is old enough to work with your php/environment. Since drush versions (which are reflected in the git repo branch names) mimic drupal versions it should not be too hard to find a suitable drush version, knowing that drupalphp dependencies are as follows:

  • drupal 6 – PHP 5.2.5 or higher
  • drupal 7 – PHP 5.2.5 or higher (>=5.4 recommended)
  • drupal 8 – PHP 5.5.9 or higher

For the rest of us, whose setup is not THAT hopelessly outdated… 🙂  let’s continue with installing composer:

– – – Install composer – – –

1. Get the composer-setup.php script using the php command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

If you feel security-freakish then go to the composer download page to verify the SHA code to make sure your downloaded file is correct.

The composer-setup.php file is what will actually install composer.

2. Choose a good location for composer (preferably in within your PATH, for easy invocation).

In my case, since I have a ~/bin dir which is in my PATH, I installed composer there.

3. Install composer
From within your chosen directory run
php composer-setup.php

Alternatively, to install a specific composer version you could run, e.g.
php composer-setup.php –version=1.0.1

The list of composer versions is available here: https://getcomposer.org/download and also there are direct download links for the specific composer versions (in case the composer-setup.php script above does not work).

4. You now should have a composer.phar file in your directory of choice. Use it to install drush. drush could be installed per-project (i.e. per drupal web-site) or globally for the user.

composer require drush/drush:7.x – get the latest 7.x version
…or…
composer require drush/drush:7.1.0 – to get version 7.1.0 (look up the drush versions in the drush git repo: https://github.com/drush-ops/drush[.git])

After doing the above you will have a vendor dir structure under your chosen directory and in it, in vendor/bin/drush will be your drush script. Now, that’s great and all, but you’ll probably say “hey, but this way the drush command is not in your PATH!?” You’re right! What I did to fix this, was create a drush directory in my ~/bin dir and inside it add a drush7 dir where to install drush v7. I then symlinked the drush php file from the ~/bin dir (becasue it is in my PATH) and this was I have drush7 available on the command line 🙂

$ mkdir drush
$ mkdir drush/drush7
$ mv vendor drush/drush7
$ ln -s drush7 drush/drush7/vendor/bin/drush

Similarly you can install and create links for a drush6 and drush8 (if you need this versions) and thus have any version of drush available on the command line.

Now… the drush installer pages say that there is a way to install drush globally (using the ‘global’ command with the require drush command above… but I could not get that working for the life of me and I don’t recommend going that route. The above works and is relatively easy to understand and perform .. and it WORKS 🙂

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

Set your Twitter account name in your settings to use the TwitterBar Section.