Community Documentation

Installing Drush on Shared Hosting Accounts

Last updated May 4, 2013. Created by Anthony Pero on June 7, 2011.
Edited by derek_slis, screenack, cedewey, juampy. Log in to edit this page.

  1. If you don't already have shell access, request access to SSH for your shared hosting account (f.e. for Hostmonster: open a new support ticket with Hostmonster Tech Support (UPDATE: Shell access can now be enabled from cPanel for some hostmonster hosting accounts). For other Hosting services you may need to upgrade to use SSH.)
  2. Once you have received SSH access to your site, open a new Terminal and login to your site by typing the following ssh username@yourdomain.com or any additional user login string provided by your Hosting service
  3. Enter your password when prompted
  4. By default, you should be in your home directory (~). The '~' is an alias for your home directory. On Hostmonster, and nearly every other Linux shared hosting situation, your website directory is located at ~/public_html or more specifically /www/htdocs/username
  5. Confirm you are in your home directory by typing the bash shell command ls, which will list the files and folders in the current directory. On Hostmonster, you should see public_html/, public_ftp, and a bunch of other files. Make special note of a file named .bashrc, as we will be editing it later.
  6. Download Drush by typing wget http://ftp.drupal.org/files/projects/drush-7.x-5.8.tar.gz, replacing drush-7.x-5.8.tar.gz with the current link. The easiest way to do this is to go to http://www.drupal.org/project/drush and right click on the tar.gz download link, then select "Copy link location" (or the IE equivalent), and simply paste it after wget in the terminal. Hit enter after completing this step, and watch as the command line downloads the tarball to the current directory
  7. Next, type clear and hit enter. This will clear your screen, and give you a little more breathing room. Do this as much as you want to throughout this process
  8. Now that you have a nice clean screen to work with type ls again, to list your directory
  9. Highlight and copy the drush tarball listed
  10. Next, run the following command, pasting your tarball in place of the one listed here: tar -xvzf drush-7.x-5.8.tar.gz. Watch as the tarball is unpacked
  11. Type ls again to confirm that you now have a folder named drush in your home directory
  12. Delete the tarball by typing rm drush-7.x-5.8.tar.gz. Make sure to substitute the tarball listed for the one you downloaded.
  13. Next, in order to use Drush across our installation, in all of our subfolders, we need to add a line to our .bashrc file. To do this first confirm you are still in your home folder (cd ~) and then type the following: nano .bashrc. This will open up .bashrc in a text editor named nano. Locate # User specific aliases and functions. Underneath that, add the following: alias drush="~/drush/drush". Save the file by typing ctrl+O (O as in Omega, not the number 0). Exit nano by typing ctrl+X.
  14. Type source ~/.bashrc to refresh the alias list and allow the new drush commands to work.
  15. Confirm that Drush is working by typing drush at the command prompt and hitting enter. You should see a list of drush commands. If you do, then success!
  16. If the previous step doesn't work, type exit to end your SSH session, then log back in (See step 2) to restart your session. This refreshes .bashrc and allows the new drush commands to work. Some hosting providers such as Go Daddy use php-cgi in the command line instead of php-cli. The former is not compatible with Drush and if this is your case you have to locate php-cli and then add the following lines to your ~/.bashrc or ~/.bash-profile file:
    export COLUMNS
    alias drush='/usr/local/php5/bin/php ~/drush/drush.php'
    alias php='/usr/local/php5/bin/php'
  17. You have now added drush hot sauce to your shared host. Awesome!

Once again, this should work on any shared hosting Linux platforms that allow shell access. On Hostmonster, you have to specifically ask them to turn it on. If you do not have a .bashrc file in your home directory, try making it by typing touch .bashrc. You can also try using a file named .profile, .bash_aliases or .bash_profile, depending on your server's setup.

Editorial Comments

For all those who didn't really understand the instructions and are just trying to follow it as it is written, here's a bit of advice: only use Drush if you start to understand it, even a little bit. Shell commands and Drush commands are very powerful and not recommended for learning on production sites or sites with a live server deadline, because you can mess things up very quickly. Your Shared Hosting support won't be happy if you create code loops through failure.

Another bit of advice: If you are not a full-time developer, you should always use the stable non-beta releases of Drush, and should never use the additional -y command to avoid the security question "are you sure you want ... ? y/n.

To put it another way: Read the instructions twice, understand what the commands mean and what they do, don't rely solely on copy/paste. In the long run, you will save your self time--which is the whole point of Drush in the first place.

Let's take the alias command as an example; you can exchange the .bashrc alias line with something else like alias ddd='~/drush/drush' instead of alias drush='~/drush/drush'. This actually changes the way you use the Drush command later. Your commands will start with ddd [your command] then, instead of drush [your command]. And you can also add other aliases of course, like: alias dddl='~drush/drush en' , which simplifies thee often-used Drush 'en' command from drush dl to dddl. In short, it is well worth your time (and safer) to go ahead and learn how to properly use Bash commands, if you plan on using Drush.

The Drush Documentation is a great place to start. It will teach you about Drush commands, and how to use them.

Comments

drush command not found after following each step

I have followed the above instructions to the letter and when I log back into remote server I keep getting drush: command not found.

One thing I did notice was that my .bashrc was empty. I then created one by typing touch .bashrc and it doesn't come up when I type ls when in my home folder. I can edit it with the nano command but it still isn't listed. What could the problem be?

If you had an empty .bashrc

If you had an empty .bashrc file, you need to add your alias to that file, not create a new one.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Thanks for your reply. I did

Thanks for your reply. I did just edit the .bashrc file to begin with but when I got the drush: command not found I created the .bashrc file.

Are you on

Are you on Hostmonster?

Verify that your folder structure is ~/drush/drush.php, and ~/drush/drush

Try copying this into your .bashrc document:

# .bashrc

# User specific aliases and functions

alias drush="~/drush/drush"

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

That's what mine says, on Hostmonster. It said everything except alias drush="etc..." when I first opened it.

If you are not on hostmonster, see if you have a .bash_profile file in ~, and add the line to that file instead.

If none of this works, try typing alias drush="~/drush/drush" at the command prompt, and see if drush works then. If it doesn't work then, you need to try starting over, because something didn't download or unpack right. If that does work, then the issue is with the bashrc file. You may need to ask Hostmonster for support.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Now working!

Thanks so much for your advice @Anthony Pero I now got it working by typing alias drush="~/drush/drush". Thanks for a great tutorial.

Just to be clear: typing

Just to be clear: typing alias drush="~/drush/drush" at the command prompt is not persistent. It will only work for your session. As soon as you close your terminal, it won't work anymore, and you'll have to type it again. This was just to test to see if Drush was installed correctly. If you got it working that way, then it's installed correctly, and the issue is with the .bashrc file. Something is not right. Hostmonster's tech support is awesome, and they will get you squared away.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Hi again, thanks I figured I

Hi again, thanks I figured I had to create a .bash_profile as well in order to have a permanent drush set up rather than temporary as you described above. Putting the drush alias into .bash-profile as well did the trick. I'm not with Hostmonster but another shared hosting environment.

I've now come across a new problem in that my site-aliases (as opposed to drush alias) just keep returning "jailshell: drush command not found" - but I realise that is another issue entirely and not covered by this post so will go a hunting elsewhere for answers. Of course if you can point me to any info on that issue please do.

Thanks for all the support so far.

getting drush working remotely on hostmonster.com site

I had drush installed and working fine if I logged in via ssh to the site; however, I was wanting to be able to use aliases and was getting the message:

bash: drush: command not found

I ended up adding:

'path-aliases' => array (
'%drush' => '/home7/{your hostmonster username}/drush',
'%drush-script' => '/home7/{your hostmonsters username}/drush/drush'

to my drush aliases file and then I was able to do what I wanted. I hope this helps if anyone else is having this trouble. I do agree that Hostmonster support is top notch but I did not need to call them for this.

Peace - Anthony

p.s. keep in mind that they occasionally move home around a bit - on my install the actually directory was /home7 - I tried just using ~ but that did not work as it seems to want an absolute path.

A short cut for the lazy

You can make it a bit easier by replacing lines 6-12 with the following:

After confirming that you are in your home directory as per #5 type the following statement

wget -O - http://ftp.drupal.org/files/projects/drush-7.x-4.4.tar.gz | tar -zxf -

replace http://ftp.drupal.org/files/projects/drush-7.x-4.4.tar.gz above with the current link.

(I find it easiest to assemble the statement in notepad or similar, to make sure it's absolutely
correct, and then cut and paste into my terminal, but any way that works is good.)

This will download drush and create a directory called drush in your home directory and expand the contents of the tar file in one nice clean step.

[Optional - or just skip to Step 13]

If there is any doubt that things worked you can verify by typing:

cd drush
ls

You should see something like

LICENSE.txt commands drush drush.info drush_logo-black.png includes
README.txt docs drush.bat drush.php examples

then type cd ~

to get back to your home directory and carry on with step 13

P.S.: Thanks for the great tutorial.... solid work!

Works on Bluehost

I just want to confirm for any folks who might be wondering, that this installed fine on Bluehost. Just follow all of the instructions above. But the first thing you need to do is enable ssh access in CPanel. It is in the security section of CPanel.

It was very easy and now I can use Drush on my Bluehost account! Thank you very much for this easy and concise tutorial!

managed hosting on hosteurope ??

Anybody who knows a solution for the managed vserver on hosteurope? No access to .bashrc, support says, they can't do anything about it...

try .bash_profile

try .bash_profile

EDIT: Alternately you can always type in the alias at the command line every time you log in.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Drush on Shared Hosting

One problem I ran into on many shared hosting environments is that only php CGI is installed. I've read in some places that drush can run with php CGI, but I was not able to make it work correctly without php CLI. Drush is already configured and ready to use.

edited by silverwing - removed potential advert sentence

A NOTE TO POINT 15:What this

A NOTE TO POINT 15:

What this point does not make clear is that drush commands will only work when run from inside your drupal install directory!

If you are outside your drupal installation folder, which you could easily presume from the way the above guide is written, and try to test your install of drush, you will at least receive this type of error

A Drupal installation directory could not be found                       [error]

so first enter your drupal install directory with the normal cd directory_name command and then run a drush command and it should work.

Thank you for pointing this

Thank you for pointing this out. It is a good tip. However, it is not strictly true. Some Drush commands work system wide, other wise you wouldn't be able to download drupal and install it with Drush. The command given in Step 15 will work in any folder, anywhere in your system.

The great thing about the Drupal documentation is that any one can edit it. Please feel free to edit the point so it reads more correctly in the future.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Got it to work...sort of.

It seems I have installed it correctly and the path seems to work. Although I have to manually input it every time I log in. I do have a problem though. I get this error even if I'm inside a drupal directory.

/home/SITENAME/drush/drush: line 39: tput: command not found
Content-type: text/html

Okay, I found out the problem

Okay, I found out the problem is at executing the script part. I had to set up the alias like this...

alias drush="/usr/local/php52/bin/php-cli ~/drush/drush.php"

the "/usr...php-cli" part is the location of the php command line interface which executes scripts, I assume. Also, php52 is the version I'm running on my shared host. Make sure you do the same thing. If you don't know what yours is, check the status report in your hosted drupal site and check the version you're using.

I also noticed that after creating the .bashrc file I got a weird looking -bash-3.2-$ for my command prompt. I didn't like and found out that putting this code in the .bashrc file help put it back to normal interface.

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

My host was Siteground and I hope this message helps anyone else trying to add drush to their site.

If you can still edit your

If you can still edit your post, could you change the title to reflect that this is the solution on Siteground? That will help in search results.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Step 14

I see that I have to repeat step 14

Type source ~/.bashrc to refresh the alias list and allow the new drush commands to work.

every time I want to use Drush in my shared hosting.
Otherwise it says "Command not found" when I type drush in the command shell.

TheodorosPloumis.com
Freelance Drupal developer

strike

strike

I got as far as step 14While

I got as far as step 14
While in the bashrc editor I deleted some of the text by accident while backspacing just below "# User specific aliases and functions." so I exited bashrc and went back to step 13.

Don't remember what happened after that but I exited putty altogether and when I tried to get back in I got error
-bash: /home2/mysite/.bashrc: line 4: unexpected EOF while looking for matching `"' - bash-3.2$

Typed drush and got "Command Not Found".

At that point I just deleted all my Drupal files and reinstalled with a clean database.

My question now is how do I get rid of drush so I can start over clean? Or what do you recommend?

Thanks
Dave

Delete the folder where you

Delete the folder where you unpacked drush. Ask your host if there is a backup copy of your .bashrc file, or if they can provide a fresh copy for you. This should restore everything. If your .bashrc file is fine, all you need to do is remove the drush directory.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

If you are on hostmonster,

If you are on hostmonster, here is what my .bashrc file looks like... you may just be able to copy this into yours, without deleting drush, and drush might work, then.

# .bashrc

# User specific aliases and functions
alias drush="~/drush/drush"

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Bluehost is now looking into

Bluehost is looking into the problem. If not a fix I'd like to know if someone else might have the bashrc code for bluehost maybe?

Lastly, how do I prevent this from happening again?

Thanks folks

Their response not very

Their response not very helpful at all. I haven't touched this file.

>>Looks like you have some custom settings in the .bashrc file. The error message you gave is says it has a syntax error.
Have you tried removing or commenting out the line that says: alias drush=~/drush/drush?

For alias's, you may need to put single quote characters (') around the ~/drush/drush for the alias to work.<<

Post the content of your

Post the content of your bashrc file here. Surround it with the code tag.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

That last line appears broken to me

Not much in this file...

# .bashrc

# User specific aliases and functions
alias drush=~/drush/drush
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

You are missing the quotes

You are missing the quotes around the drush path... this is what you need it to say:

# .bashrc

# User specific aliases and functions
alias drush="~/drush/drush"

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

Bluehost restored the file

Bluehost restored the file after all. They also placed a backup in /etc/bashrc

I will keep your copy handy in case I ever need to do this.

Thanks a lot!

Remote Drush calls with GoDaddy Shared Hosting

GoDaddy Shared Hosting allows you to create your own bash aliases in ~/.bash_profile, which is useful for using SSH to log in and use Drush on their servers, but is useless for remote calls to Drush via SSH. A call to drush @remote-site status will complain bash: drush: command not found.

To get remote calls working, you must specify GoDaddy's PHP binary in php and the path to drush.php in %drush-script for the remote alias:

$aliases['remote-site'] = array(
  'php' => '/path/to/php',
  'path-aliases' => array(
    '%drush-script' => '/path/to/drush.php',
  ),
  // ... additional alias config
);

Without the .php extension, Drush will try to execute drush ...remote...command... over SSH, which sucks because there is no drush command on GoDaddy's PATH. This way, Drush will call /path/to/php /path/to/drush.php ...remote...command... over SSH instead.

As of this writing, GoDaddy's PHP binary is /usr/local/php5/bin/php.

I was surprised that it took me three hours of useless blog posts to figure this out on my own.

Where do you put this code?

@aberger ,
Many thanks for this. Does this piece of code go into .bash_profile?

Your help is appreciated.
RD

many thx

saved me my weekend ...

It worked!

Thank you for this procedure!! Very good detail on the instructions. I had to copy over example.drush.ini over to the drush sub-directory and remove the comment notation from the following line: safe_mode= and then it worked great. Thanks again!

-Frederico Garza

I can't thank you enough for this post!

Followed your checklist and worked like magic.

Now because I'm sooooooo new to command lines and drush and such, before actually doing doing anything with it, I need to ask. So in my public_html I have several subfolders, each of them is a site. I do not used a shared installation of drupal, but there is a drupal install for each folder.

Let's say:

-public_hmtl
- SiteA
- SiteB
- SiteC
and so on...

So if I want to execute a core update for Site A ONLY, let's say, ( not Site B, Site C), etc. Where exactly should I be?
in

public_html/SiteA or in public_html/SiteA/sites/default

And for sure it won't affect anything above that folder, right? The other installs are safe and sound, right?

Almost sure that public_html/SiteA is the answer but I would like to confirm, before ...well...crying. :)

Drush commands given will

Drush commands given will work for your site and your site only, as long as you are inside the Drupal directory, in this case SiteA.

Thank you!

I have my test site in folder SiteA and will do all drush tests there so I wanted to make sure.

Oh but I forgot another very important question

I have already SUCCESSFULLY performed the update of drupal core for SiteA, now I have a drupal website ALSO in the root.
Will executing the drupal core update drush command right in the public_html folder, affect the websites in the subfolders ???

I don't believe so. I'm

I don't believe so. I'm pretty sure of that.

Anthony Pero
Project Lead
Convergent Creative Web Design
http://www.convergentcreative.com/

It doesn't. I can confirm it.

Went ahead and just did it. No effect on the subfolders. I suppose it follows the sites/default/config file and acts from there.

My success on 1and1

Just to confirm how I went with a shared hosting package on 1and1.

I followed the instructions and all went well. A couple of changes though. On my host I had to put the following lines in .bash_profile

alias drush='/usr/local/bin/php5 ~/drush/drush.php'
export COLUMNS

However, to get drush to work remotely I had to add the following to the aliases.drushrc.php file (names changed to protect the guilty):

$aliases['remote'] = array(
  'remote-host' => 'remote.websitehome.co.uk',
  'root' => '/kunden/homepages/your-remote-directory',
  'uri' => 'remote.websitehome.co.uk',
  'remote-user'  => 'user',
  'php' => '/usr/local/bin/php5',
  'path-aliases' => array(
    '%drush-script' => '/kunden/homepages/bit-in-between/htdocs/drush/drush.php')
);

Good luck!

Added a local PHP.INI and solved my memory problem

I've recently struggled with this issue and after many failed corrective measures, here is how it was overcome. The error I was getting stated that the allowed memory of 57000000 was exhausted. I was simply trying to upgrade drupal core using the DRUSH UP DRUPAL command. When I used the various commands to determine how much memory I had my shared hosting service reported 128MB.

1. Drush will seek and load a php.ini file found in the drush folder before it searches out your PHP CLI php.ini location. So, grab the example.drush.ini file from examples folder (within the drush folder) and rename it php.ini and place it in the drush/ folder. There was only the memory_limit and the error_reporting lines active.

2. After I did this I started gettting errors that it couldn't find a valid drupal install..., bootstrap errors occurred even though I was running the command from public_html file. So I added to my new php.ini file these commands:
zend_extension="/usr/local/IonCube/ioncube_loader_lin_5.2.so"
extension=timezonedb.so
extension=mailparse.so
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

3. After adding these the command finally worked. If you review your php.ini file found in the CLI location [my case it's /usr/local/lib/php.ini] you will see many other commands. You may need to add some of these other commands if you have other errors. Add them one at a time and test.

Hope this help those who are struggling.

Thanks emag!

This solved my problem. I searched the web for 3 hours until I stumbled upon this comment. Thanks emag!
Is this some kind of bug ?

Awesome instructions!

Installed Drush on Bluehost in a minute, thx guys!

Page status

Needs copy/style review

Log in to edit this page

About this page

Drupal version
Drupal 5.x, Drupal 6.x, Drupal 7.x, Drupal 8.x
Level
Beginner, Intermediate, Advanced
Audience
Designers/themers, Programmers
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here