Installing Drupal 7 Using SSH & Drush Tutorial

Installing Drupal using SSH & Drush

Installing drupal using SSH & Drush

In this tutorial I'm going to show you how to install Drupal using the command line. This is how the experts tend to prefer to do their installations. It is fairly technical and it does involve several Unix commands which might seem rather cryptic if you're not used to using them. If you are a Linux person, you're going to feel right at home. If you're not, don't worry! I'm going to give you all the steps you need. If you still don't feel comfortable using the command line, you can always go back to the FTP method we reviewed in Installing Drupal Using FTP. Even if you do prefer the less "techie" FTP method, it doesn't hurt to have some familiarity with what is involved in installing and working with Drupal from the command line.

Drupal Prerequisites

There are a few prerequisites we need to go over before we can start our install.

First, you'll need web hosting that meets Drupal's requirements and enables you to SSH into the server. SSH is a method for giving your command line access to your web server. It is considered a more advanced feature, and is less commonly found in general web hosting packages. You'll want to check with your hosting provider or server admin to see if your server is set up for it. For more information on the types of hosting available see Installation Requirements and Options

Other Options

If you don't have hosting with SSH, you can get a free trial account at webenabled.com. This will still allow you to follow along with this tutorial.

Also, if you have a Mac or Linux machine and have a web stack installed, you can work locally using your computers own command prompt.

To work with a remote server, you will need a terminal emulator on your personal computer. On a Windows machine I recommend using Putty. You can download the stand alone version by going to the Putty site by GreenEnd. The portable version of Putty is also included in the Webmaster Tools Kit.

On a Mac you can simply use an application called Terminal that's included as a part of your OS. For more on SSH clients, see Essential Web Masters Tools.

Command Line Installation

There are two general ways of doing a command line installation: 1) using only Unix commands or 2) Using a library of helper scripts called Drush. Drush is a command line interface for Drupal. It provides a "swiss army knife" of tools that simplify many of the common things we want to do on our server. Effectively, it's a set of command line macros for managing Drupal.

Let's take a look at a comparison between the two steps.

  • With our Unix only command, the first thing we would want to do is set up our database. Then we would go and fetch the Drupal archive, extract the archive, and move the files to where we want our Drupal sites. Then we can run back to the web browser and run through Drupal's installer.
  • With Drush, our first step is to create a database (same as the Unix version). The second step is to go and get the Drush archive, extract the files, and create an alias so that we can use it anywhere on our server.

Now we can use Drush's commands to do the rest of the steps. Drush has a simplified version for fetching our Drupal archive and moving the files. The last thing we can do is a one-line install of Drupal. It might look like there is a little more on the Drush side, but in reality it A) does simplify things a little bit during installation but B) gives us a lot of extra tools to help us manage our site down the road.

Getting Started

To get started, we're going to log into our web server using our SSH client. I'm going to go ahead and launch Putty. If your on a Mac, this is where you would want to use the terminal application instead. I'm going to put in the domain name of the server I'm trying to connect to and now it's going to ask me for my login credentials. So I'm going to put in my username and my password. Now we're connected into our server.

Now I can start installing Drupal using just the command line. We're also going to want to clean this up so it's easier to read. The first step is to create our database. Many hosts offer database administration tools that enable us to do this with a web browser. We took a look at a couple of these in Installing Drupal using FTP.

Command Line

In this tutorial, we'll use the command line. Creating a database only requires a single command. What this command is doing is telling the MySQL engine that using the user "Acme Example," we want to create a new user database called AcmeExam_Tutorial. Click enter. It's going to ask me for a password for security reasons, and our new database is created. We check that by looking at our PHPmyadmin. Here we see our new database. Of course there are no tables in this new database, but that's going to up to Drupal's installer to put the information in here.

The next step we'll take is to download Drush from Drupal.org. Before I do that I want to get a handle of where I am on my web server. I'm going to issue an ls command. The ls command gives me a list of files and directories of whatever folder I'm currently in. What I notice is that I'm one level below public_html and that's good because that means I'm in a non-web accessible directory. This is a good place to install Drush

Now I'll download it from Drupal.org. To do that, I'm just going to use the Wget command. The syntax is really pretty simpl; Wget, followed by the name of the file you want to transfer, and save on your local machine. Click enter, and we see that it transfers and downloads pretty quickly because we are just going from server to server.

I perform another ls command and we see that our archive file is saved to our server. The one issue is that this is in a tarball format so we need to uncompress the file before we can use it.

To do that, I'm just going to issue a tar command (basically a tar and two arguments). Then, we'll have tar and these switches, followed by whatever the name of the file is we are trying to unzip. If you want to know more about what these switches are, I recommend looking at tar's manual. Click enter, and we see that it's unzipped.

Now I do an ls command and we see that I have the original archive and we also have a Drush folder. I can now go into that folder and run Drush. If you just run Drush without any arguments you see that it's going to give you back a list of different arguments you can use with it to help you do administrative things with Drupal.

Setting Up an Alias

There is one last thing we are going to want to do. Right now, I can only run Drush commands inside of this directory but I'm going to want to be able to do it anywhere on the server. So we're going to set up an alias. I simply put in the command alias and Drush= and the path on my server to where the Drush files are. Click enter and now whenever I use the word Drush it'll be able to find the scripts no matter where I am on the server. Let's use Drush to download our Drupal files. To do that I do want to move over to our web directory where our web files should go. We are currently in the Drush directory, so I move down a level and then move up to the public html (which is also aliased as www). I go to cd../www and if we do an ls here we see there are no files.

Downloading Drupal

To download Drupal, I simply go and do Drush dl for download and then I give it the project name I want to download. Since we are downloading Drupal core, it's just simply Drupal-7.38 (since that is the current version of Drupal). Now it's doing a weget to pull the files over and then it's automatically un-archiving them for us. The other nice thing is that I didn't have to use that long URL string, and instead I can just put in the project name.

When we do an ls we see that our Drupal files are sitting here. The problem is they are one level too deep. I need to move them and bring them back so I'm just going to do a couple Unix commands that will move these files.

  1. Do an MV which is Unix for move drupal-7.0/
  2. Move all the files and into your current directory dot.
  3. Do another ls. Now they're moved but there is one file that did not get moved. If we go into the Drupal directory we can see this. It's the htaccess file; because it's got that dot it's a special file type so we're going to have to move that one separately.
  4. Issue the same command MV drupal-7.0/.htaccess and dot.
  5. Perform another ls. Now your htaccess file is there.
  6. Tidy things up by removing our drupal directory. Do an rm and drupal-7.0. Now we've got all of our files moved ready for installation.

One of the neat features of Drush is that we can do a single command line install of Drupal. Note that this command is really complex so I'm going to break it down. The first thing is that we are telling Drush that we want to do a site install. The next parameter is do we want it to be minimal or standard; generally I recommend doing a standard install so that's what we have selected here. The next two parameters are just the login information for our super user; we need to give it an account name and we need to give it a password.

Connecting Drupal to the Database

The last piece of information is our string telling Drupal how to connect to our database. So this basically says that we want to connect to MySQL. The database user is Acme Exam, its password is demo1234, it's on our localhost, and we want to connect to the database AcmeExam_Tutorial. We simply click enter, confirm that we want to use this database, and it's going to start the install. 

Incidentally, you can use this command to actually do a re-install in case you want to wipe your database and start with a fresh version of Drupal. Now it's done so if we want to check out our website, we simply open up our browser, go back to our site URL, and there is our site up and running. Drush is a very powerful library for managing Drupal.

Summary

We only scratched the surface by seeing how Drush is used during installation. Typically the next steps you take after installing Drupal is to go out and install several different modules. Drush also makes this a snap, particularly if you are using the popular Drush make add on which allows you to define sets of modules that can be automatically installed together. Now I do realize that this tutorial was more technical than the rest of the getting started with Drupal course. But even if your not a command line techie, I hope the video opened your eyes to some things SSH and Drush can do. You might find them handy as your Drupal skills grow.