Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Installing Drush on a Shared DreamHost Account

Parent Feed: 

[box type=”note”]If you have issues with these directions, please read the alternate directions for installing on a shared host manually without using Pear. MediaTemple is one provider where you must use the alternate directions to get Drush working.[/box]

One of the easiest and most convenient ways to get your hands on Drupal is on a shared hosting environment. It’s pretty much where everyone is going to start from unless you happen to have a giant long-term budget for your own hardware.

You have a number of options when it comes to hosting and at one time or another I’ve tried a lot of them. Three companies that have managed to keep me the happiest though are A Small Orange (use coupon 15-off to get 15% off; no affiliate), DreamHost (no affiliate) and MediaTemple. I’ve found DreamHost in particular to be pretty impressive when it comes to hosting a lot of one-off sites on my very inexpensive shared plan. I even use it when rapid prototyping for clients.

The best part though is that with DreamHost I can use SSH and Drush the way I normally would like to on a dedicated or virtual server. Set up is a bit more complex than normal, but, once it’s set up for your user it’s smooth sailing.

Before you can do any of this, you will need to make sure you enable SSH for the user you assigned to the  domain you want to use Drush with. You can find these options under the Manage Users section of the DreamHost panel. From there open up your favorite SSH client and log into your site (PuTTY works well on Windows, you can just run ssh from the command line on Mac or Linux).

Since you’re in a locked-down shared hosting environment, you obviously can’t make system-wide changes. The easiest way to install Drush is though Pear. Pear, by default, wants to make system-wide changes. Since we can’t do that in a shared environment, our first order of business will be to set up a new instance of pear just for our user.

Once logged in, and in your user’s home folder, run:
pear config-create ${HOME} ${HOME}/.pearrc
pear install -o PEAR

Now you have your own instance of pear, but you still can’t use it yet. To fix this, we will edit our .bash_profile and add in the path to the most recent PHP version DreamHost provides, as well as adding in our pear directory early on in this user’s PATH.

Open ~/.bash_profile in your favorite editor:
nano ~/.bash_profile

And add these lines at the bottom of the file:
export PHP_PEAR_PHP_BIN=/usr/local/php53/bin/php
export PATH=${HOME}/pear:/usr/local/php53/bin:${PATH}

Finally, re-load the file so the changes will take effect immediately:
. ~/.bash_profile

Now we have the newest version of PHP and our custom version of pear available to us, to check this out, you can run these commands:
which php
which pear

Pretty cool, eh? Lastly, just run the usual install command for drush to install it:
pear channel-discover pear.drush.org
pear install drush/drush

Now you can use drush from any site under this user as you would anywhere else (try running `drush help` for some cool examples). You can repeat this process for any other SSH users on your account. A one line tl;dr version of this process is included below for your automated and repetitive pleasure. Enjoy!

tl;dr: Get drush running on DreamHost by running this line in SSH:
pear config-create ${HOME} ${HOME}/.pearrc;pear install -o PEAR;echo "export PHP_PEAR_PHP_BIN=/usr/local/php53/bin/php" >> ~/.bash_profile;echo 'export PATH=${HOME}/pear:/usr/local/php53/bin:${PATH}' >> ~/.bash_profile;. ~/.bash_profile;pear channel-discover pear.drush.org;pear install drush/drush

[box type=”note”]

Robin Monks has a passion for openness and freedom in technology and he’s spent the last 8 years of his life developing, supporting and maintaining open source software. He’s part of the panel of Drupal community experts who authored The Definitive Guide to Drupal 7 and currently provides independent consulting services. Reach him at 1-855-PODHURL.[/box]

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web