Drush for Drupal: Command Line for Drupal

I am not new to Content Management Systems and have been developing websites for quite some long time now. I have used CMSs like Joomla, Drupal and WordPress (yeah its not just for blogging). Add to that a few others like Silverstripe etc. Well I enjoy developing websites using CMS as it eases a lot of your work. No more trouble about entering data directly into database or writing HTML code. Easy to install plug-ins, themes and what not. But this case which I am going to mention is really interesting and fascinating. So please read on =)

I tried using Drupal two years back when I was just looking at the various CMSs available. I like the flexibility it had over any other CMS but then the interface was really difficult to navigate (or so my lazy mind felt).  There were not many good free themes  available and also the modules were also less as compared to Joomla and WordPress. Since then I have been building websites majorly on Joomla with WordPress as well for small or quick projects. But then I kept reading Drupal is really cool and you can add a whole new level of functionally to it once you get a good hand at it. Those comments bothered me. At times I wanted to do some stuff in Joomla and then realized that its just too inefficient or rather lengthy process to do those.

A few weeks back I started on a new website. I thought of giving it a shot in Drupal this time. So installed it and started working. One feature which didn’t work for me was the Plugin Manager. Its actually a pretty good plugin which gives you a great control over installing, updating both modules and themes for Drupal. So I was looking for a really rapid development using this. But alas no computer is perfect and no hosting is perfect as well. I am using Godaddy Grid Hosting and after a lot of search I found out that they do not support ftp_connect() php function which spoiled the party for me. (Please if anyone knows how to run Plugin Manager on Godaddy Grid hosting please share it with me). So I was back to looking for something which will help me with rapid Drupal Website Development. After a few searches I stumbled across this Drupal project called Drush. Drush basically stands for “Drupal Shell” and its a command line utility to install modules, themes, updating and do much more. All in all its gives you the control of your drupal installation  through a command line interface. (Which developer won’t love it =D). I downloaded it but really had a hard time trying to figure out how to make it work.

Well as they say “Google when in trouble” so I did just that. I was getting the error

Content-type: text/html

drush.php is designed to run via the command line.

They had a few tutorials on fixing it. The best amongst them which worked 90 percent for me was this one by Joshua Riddle again as I figured out it was basically a Godaddy problem which was not allowing Drush to run properly. Basically Drush requires itself to be run by php-cli which by default is not accessible in command line by the hosting. So in order to make it work I was required to add an alias to the drush command I intended to use with the exact path of the php executable. The line which was required was:

alias  drush=’/usr/local/php5/bin/php ~/html/drush/drush.php’

So this used to solve the problem whenever I entered the above in the shell. But there is a need for automation so that things get taken care of for always. So I added this line to .bashrc file of my directory. But it didn’t work out somehow (Again it would be great if someone can explain that as well). So I “Googled” and lo I got the answer again. The solution was presented on this Wiki How article “Install Drupal with Drush 2”. The point which solved the matter for me was

echo “alias drush=’/usr/local/php5/bin/php ~/drush/drush.php'” >> ~/.bash_profile
source .bash_profile

This done now I can log into my hosting and control installing any module, theme directly from the command line. And first of all its fast and secondly its really easy. Say for example you want to install the Dynamic Display Block Module module in your drupal site so all you are required to do is change your current working directory to your drupal install folder. After that fire this simple command in your command line

drush dl ddblock
drush en ddblock

Done and your module is downloaded and enabled. As simple as that. Not only this you can download and install modules in bulk all you need to write a command similar to this:

drush dl cck zen es

Which will Download latest versions of CCK, Zen and Spanish translations for your Drupal version. For a detailed lists of commands you can always type

drush help or simply drush

Details about the Drush module can be found on Drush.ws. Overall its a must use for anyone who wants to develop Drupal websites very quickly. Its insanely powerful and increases your working pace 10 folds.

There are some small quirks related to installing it but once done its like a cake walk for any Drupal Developer. I am new to it but have already started to see the positive implications of this project. Thanks to the Drush team for giving us such a great tool.

Feel free to post your issues related to the module or anything related to the hosting problems. Also if anyone can figure out how the .bashrc and the Plugin Manager issue can be solved I would be very thankful.