Monday, August 21, 2017

Installing Drush on Shared Hosting (Vidahost)

I followed the guide at https://www.drupal.org/node/2366283 to install Drush on my current host of choice (Vidahost), but couldn't get Drush to work properly. Problem #1: Couldn't find CLI. Problem #2: Drush 'master' wouldn't work with my many Drupal 7.x sites.

Here's the skinny:
  • First edit your .bashrc file that Vidahost puts in the root folder and make sure the PHP alias is pointing to the CLI version of the PHP release you are using. For Drupal 7 and 8, PHP 5.6 seems to be fine:
    • Type nano .bashrc
    • Remove any aliases to PHP in the file and add the following:
      • alias php='/usr/bin/php-5.6-cli'
    • CTRL + x to save and exit the file
    • Type source .bashrc to reload your Bash file and set up the alias.
  • Install Composer in your root folder
    • curl -sS https://getcomposer.org/installer | php
    • Leave files where they are (leaves lots of files in root, but park that OCD for a change).
  • Type nano .bash_profile to add an alias:
    • alias composer="'/usr/bin/php-5.6-cli' ~/composer.phar"
    • This adds an alias to the PHP 5.6 CLI location on Vidahost - may well work for other hosts too.
  • Save your file (ctrl-X) then run your Bash file with source .bash_profile
  • Get Drush (version 8 works with Drupal 6, 7 & 8) 
    • composer global require drush/drush:8.x
  • Update your .bash_profile with another alias
    • alias drush="~/.composer/vendor/bin/drush"
  • Reload Bash file:
    • source .bash_profile
  • Type drush to see if things are working.
Fame and fortune await (etc).

2 comments:

  1. Bit of fretting on an old site - Drush 8.x wouldn't play very well with a Drupal 6 site. So installed Drush 7.x instead and all seemed well.
    Also found out that Drush sometimes doesn't deal well with .bashrc aliases, so you should add the path to PHP as the PATH variable:
    PATH=~:/usr/local/bin:/bin:/usr/bin

    ReplyDelete
  2. And there's a whole world of pain if you use MAMP (on a local environment) with Drush. Actually it's not that big a deal, just need to make sure MySQL can be found. See https://www.drupal.org/node/1651282

    ReplyDelete