Configure Drush on A Small Orange

NOTE: Drupal Console can now do a lot of the functions of Drush and may make more sense in your situation. It is a good idea to be familiar with both and use them however best benefits you.

If you use Drupal you need to use Drush.  For things that are in the Drupal UI, Drush is often more efficient (you don't need to wait for page loads just so you can clear cache or enable modules, for instance.)  However, what if you're a careless admin who forgot their password, or you need to login as a different user?  Drush will generate one-time login links for you.  Site down?  Drush might be able to help you get it back.  Point is, once you've gotten accustomed to Drush, you will never want to be without it! </soapbox>

To install Drush on A Small Orange (ASO) or other shared host, SSH into your account, and go to the home directory.  First, make sure composer is installed (it should be on ASO, but just in case...)  If it isn't:

  • Make sure curl is installed.  If not, run sudo apt-get install curl (you probably won't be able to do this on a shared host.)
  • Run curl -sS https://getcomposer.org/installer | php
  • Move composer to your local bin directory: sudo mv composer.phar /usr/local/bin/composer (actual destination could vary.  Will probably be ~/bin/composer on a remote host.)

Now you can install Drush according to the official documentation:

composer global require drush/drush:8.x

Note that I am installing the latest version of the 8.x branch.  Change this for other versions.

Create an alias to Drush by editing your .bashrc file:

nano ~/.bashrc

at the top of the file, add the Drush location to the path (probably not necessary since it is handled by composer, but wouldn't hurt.):

export PATH="$HOME/.composer/vendor/bin:$PATH"

and add the following line (at the end of the file is fine):

alias drush='~/.composer/vendor/bin/drush'

Reload your profile, and see if drush is working:

source ~/.bashrc
drush core-status

Now that Drush is running, you might want to learn about aliases.