How to Install Drush on Shared Hosting

By Nick Landis on Thursday Jun, 19th 2014

Since the new version of drush has come out and now requires Composer, most of the guides I've seen online don't work anymore.  Hopefully, this guide will prevent others from the headaches I went through getting this setup on my host.

First, I'm assuming you already have SSH access to your host.  If not, go get that done and come back to install drush.  It will be a little different depending on your hosting provider.

Make sure you're in your home directory

cd ~

Next, download Composer to your home directory

wget https://getcomposer.org/installer

You should now have the installer downloaded to your home directory in a file called 'installer'.  Since most hosting providers are still default to php5.2, we need be sure we are using php5.3 or higher.  On my host, I was able to use the cpanel to upgrade to php5.4.  Confirm your php version with this command

php --version

You should have something like this show up.

PHP 5.4.28 (cgi-fcgi) (built: May  5 2014 00:18:15)

Copyright (c) 1997-2014 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

    with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies

If that didn't work try someting like this.  On HostGator, the upgrade did not affect the home directory.  I was able to do this with this command.  "/opt/php53/bin/php" is the path to php5.3  it may be different on different servers.  Confirm with something like this if your path was like I said earlier.

/opt/php53/bin/php --version

Sometimes it can be something like this.  this is an example for running drush on BlueHost shared hosting

/usr/php/54/usr/bin/php-cli --version

Be sure it says PHP 5.3 or higher before continuing...

Install Composer

php -f installer

Now download drush. You may need to add the "--no-check-certificate" at the end to work properly...

wget https://github.com/drush-ops/drush/archive/master.zip

Unpack the zip file

unzip master.zip

That puts a directory callded 'drush-master' with all the drush goodness in it.  Change the name to just drush and go there.

mv drush-master drush

cd drush

Install Composer dependencies.  There may be some tricks that will need done to get around the lack of "CLI" for php on shared hosting.  One way is to check if you can use the "php-cli" command.  Check with "php-cli --version".  If you get back a non-error message.  You should be good to do with this command.

php-cli ~/composer.phar install

If that isn't working, you can get around it with something like this.

/opt/php53/bin/php ~/composer.phar install

Navigate back to your home directory. And run drush

cd ~

drush

If you get errors, there could be lots of things that went wrong.  If you needed to specify a different php version earlier, you probably need to add an alias.  Find your .bash_profile file at the end if you needed to use a specify another php version.

Edit your .bash_profile file to update your aliases to the drush command.  Here is the command.

nano .bash_profile

Add something like this to your file.  You may need to do something different.  This one worked on HostGator.  Remember the step several above where we got the php version replace the "/opt..../php" stuff with what worked in this line.

alias drush="DRUSH_PHP=/opt/php53/bin/php ~/drush/drush"

The one for BlueHost looked like this

alias drush="DRUSH_PHP=/usr/php/54/usr/bin/php-cli ~/drush/drush"

You can double check your drush version like this when everything is working.

drush --version

If everything is good, it should report back somethign like this

Drush Version   :  7.0-dev

Hope this helps.