Mar 8, 2010

Recently, I have been working with quite a few Drupal sites, and one of my favorite tools to use has become drush. For those of you who are not aware of it, drush is a command line utility (drush = DRUpal SHell) that makes management of a Drupal site much more bearable. Drush is a great tool to use and is quite simple to install on your system when you have admin rights to the box. However, what about those of us on shared hosting system? For us, we have no admin rights but if you have picked a solid hosting company, you'll have command line access and a .bashrc file (or similar e.g. bash_profile depending on your server distro).

Once you have command line access, create a directory on the server where you'll keep any programs you choose to install. I created a "bin" directory in my user's home.

mkdir bin

Once you've created that directory, use wget and the link to the latest drush version to download the tarball.

wget http://ftp.drupal.org/files/projects/drush-All-versions-3.0-beta1.tar.gz

Once it downloads, extract it.

tar xzvf drush-All-versions-3.0-beta1.tar.gz

cd into the newly created directory and make sure the drush* file is executable. If not,

chmod u+x drush

Now you have drush on your system it would be quite cumbersome to have to type the full path to the executable as well as the drush options. In order to alleviate this we have two choices: (1.) we can either export our PATH or (2.) setup an alias in our .bashrc file. I choose the latter, but I'll show you both options. First, however, you'll need to know the full path to the drush executable. Inside your ~/bin/drush directory, execute the following:

pwd

So your full path will be something like: /home/mysite/bin/drush/drush

Onto setting up the shortcuts to only have to type 'drush'

PATH option:

export PATH=$PATH:/home/mysite/bin/drush

.bashrc option:

vi .bashrc

Inside the file, you'll add an alias (press 'i' to enter insert mode)

alias drush='/home/mysite/bin/drush/drush'

then save the file (type :wq)

The downside to using the .bashrc option is that you'll have to start a new terminal session to begin using the alias (or type the same alias in the command line so you can use this session then any other session you start it reads from the .bashrc). thus, you should exit then fire up your terminal again.

From here you can execute the entire suite of drush commands simply by using the word 'drush' followed by any drush options just like you would in a normal drush install.

To recap, simply:

  • open a terminal on your server
  • create a bin directory
  • download and extract drush into the bin directory
  • ensure drush is executable
  • get the full path to the executable then either
  • 1) add the full drush path to your PATH variable
  • 2) alias drush to the full drush path and restart you terminal session

*note: instead of executing a pwd to get the path to your drush install, you could use ~/bin/drush/drush if indeed your bin is in your home directory but I think it's best practice to use full, human readable paths to alleviate any ambiguity.

Hope this helps!


This method of installation
Aug, 4 2010 - Ihsanullah

This method of installation work successfully for me.

Find the download URL of the recommended release from the Drush project page and download with WGET
cd ~/
wget http://ftp.drupal.org/files/projects/drush-All-versions-3.0.tar.gz

Extract the archive
tar -xvzf drush-All-versions-3.0.tar.gz

Set up an Alias
Create an alias for Drush in .bash_profile (this can also go in .profile or .bash_aliases)

echo "alias drush='php ~/drush/drush.php'" >> ~/.bash_profile

Optionally, specify a PHP path (version 5.2 or greater required)

echo "alias drush='/usr/local/php5/bin/php ~/drush/drush.php'" >> ~/.bash_profile

Load aliases[1] (or reconnect)

source .bash_profile


very helpful but missing one important step
Jul, 25 2010 - decibel.places

between step 1 & 2 - add cd bin

mkdir bin

cd bin

wget http://ftp.drupal.org/files/projects/drush-All-versions-3.0-beta1.tar.gz

but the rest is spot on, got drush set up in jailshell in 5 minutes - thanks from a terminal dummy!


Thanks!
Jul, 11 2010 - Mags

Thanks a million! This was exactly what I needed to know and what the guys at Drupal.org was too lazy to tell me (they said "if you need to have this explained to you then you shouldn't try use Drush"). But we all has to start somewhere right?
/Mags

Ps. Btw, you're skipping a step in the tutorial, after mkdir bin, shouldn't there be a cd bin?


Fund this helpfull to
Jul, 25 2010 - Roger

and the kind of respons you got (from "drupal.org guys") I never understand. Give a plain answer to one who asks, or don't. Nice article. Thanks.


Thank you so much! I don't
Mar, 23 2010 - Melissa

Thank you so much! I don't like to spend all day watching screencasts and this was exactly what I was looking for.


You don't have to restart
Mar, 14 2010 - Jeff

You don't have to restart your terminal session for the settings in .bashrc to take effect.

You can use 'source' or '.' to re-read the .bashrc file:

$ source .bashrc
-or-
$ . .bashrc

It you are using screen and have multiple terminal windows, then you'd have to source the .bashrc file in all of the open terminal windows.


instead of using alias, you
Mar, 9 2010 - Drupal Theme Garden

instead of using alias, you could create symlink in your bin folder:

ln -s /path/to/drush/drush ~/bin/drush


People running a site on
Mar, 9 2010 - dalin

People running a site on shared hosting are unlikely to be able to comprehend vi (heck I can't either). You might instead use nano in your example. I have yet to find a distro that doesn't have nano installed as standard.


Nice, thanks, but...
Mar, 8 2010 - Anonymous

This works indeed. However, my hosting provider has both PHP 4 and PHP 5 available, and PHP 4 is the default. So whenever I try to run drush from the shell, I get nasty errors due to the outdated PHP version.
Any idea how to set PHP to version 5 by default (or for drush alone) from a .bahsrc file?


Re: NICE, THANKS, BUT...
Mar, 8 2010 - Steven Jackson

You can put the full path to the PHP version that you want to use ahead of the drush call to invoke a certain version of PHP.

e.g. $ alias drush='/path/to/php/php5 /path/to/drush/drush.php'

Here's a link to the drush documentation:
http://drupalcode.org/viewvc/drupal/contributions/modules/drush/README.t...

The advanced section begins on line 34 and details this topic.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.