Join Tom Geller for an in-depth discussion in this video Understanding and installing Drush, part of Drupal 7 Advanced Training.
I have a secret to tell you. Full-time Drupal site builders don't use Drupal the way I've shown you throughout all my lynda.com courses, pointing and clicking their ways through configuration screens. In fact, they often don't use a web browser at all until the very end. Instead, they use a command-line tool called Drush. This isn't a module. Instead, it's something that interacts with UNIX or the command line through windows. I'll show you how to use Drush throughout this section of the course by using it to install a new Drupal web site.
But first we have to install Drush itself. We go to drupal.org/project/drush. Before downloading it, I just want to show that there is a lot of documentation for Drush. It's a very well-supported module. The main site is drush.org. We chose a bunch of commands and a FAQ and all sorts of other information. There's also a list of modules that integrate with Drush and this becomes important as you work further and further into your site. There is over a hundred of them as I record this video.
But let's get back to the project. I'll go down, copy this link, and remember because it's not actually a module, I'll go back onto my terminal and into my home directory. I am going to install it somewhere inside there, but outside of Drupal's home directory. So here I am in my home directory and the question is where should I put it? Well, the traditional place is in this bin directory. So I'll go down into there, see what's there, and then I'll get that link and uncompress it.
Now when I list again I see it's there. I can get rid of that .gz file if I want. I can see what Drush actually is by going into that directory and poking around a bit. There is a quite a lot of stuff here. The file that we are actually going to call on is this one here, Drush. The other files really just support that one. That's the main program. I am going to go up again one level. So now we are in bin and we have the drush folder right there.
In order to call up Drush, you say run the program where I am into that drush folder and then call up the program Drush, and then you issue a command. In this case, I will try help. And it works. We basically just get a list of common commands from doing that. Now that whole thing about typing ./ drush/drush and so on and so forth, those paths becomes really, really long and when we were in your web site's directory and that's where you're going to be running Drush commands usually. So going to invoke a little trick to tell UNIX to always look for this directory for commands.
It's something called an Environment Variable. There are several ways to set them, and I'll only use the techniques specific to my web host's version of UNIX. To see more, watch the section Configuring Your Working Environment in the lynda.com course UNIX for Mac OS X users. First, I'll get out of this command by hitting Ctrl+C, and I'll go back to my home directory by something typing cd. In my home directory is something called bashrc, bash resource, and it's a hidden file, so it starts with a dot.
I am going to edit that and add a line of text that will tell my UNIX system to always look in that directory. So nano. bashrc, go down under User specific aliases and functions and add this line, and then I save it. Basically, what I'm saying is take the current places that you look for such commands and add this to the end of it.
And yes, I want to save that. Then to make that effective I'll clear the screen and type source .bashrc. Now we can see if that works by simply typing drush help, where we are, and remember we're not in that directory anymore. But if what we did is correct, then this should just work, and indeed it does, but will it work from within our Drupal site directory? Let's find out. So here we are again in my home directory and I want to go into webapps and my site is lyndalynda. Yup! There's my Drupal installation.
Let's try drush help again. It worked! I should mention there are actually several ways to install Drush, and in fact you need to follow a very different procedure when installing it on a Windows computer. The details are available on the Drush Project page at drupal.org/project/drush. As we scroll up, you see it fairly near the top here, this Drush installer for Windows. For UNIX, I like the installation procedure you saw here, because it shows the nitty-gritty of how it all works.
When you're comfortable working in a specific environment, however, you will probably want to seek out a procedure that's optimized for your preference and flavor of UNIX. So we have Drush installed, but what can you do with it? I'll show you that in the next video by doing a complete Drupal installation in this folder using only Drush. We won't use the web interface at all except to check out our progress.
Drupal 7 Advanced Training was designed as a follow-up to Drupal 7 Essential Training and it also dovetails nicely with our other Drupal courses, such as Drupal 7 Reporting and Visualizing Data and Create Your First Online Store with Drupal Commerce.
- Moving a site from the development environment to production
- Hosting a Drupal site
- Moving databases with phpMyAdmin and Unix commands
- Making site administration more efficient with Drush
- Backing up site data
- Moderating comments
- Migrating from previous versions of Drupal
- Working with themes
- Creating variable layouts
- Enabling social features
- Creating an online store with Drupal Commerce