Installing and Upgrading Drupal from the Command Line

Printer-friendly versionPrinter-friendly version

The Drupal project has fond hopes of one day producing the most user-friendly content-management system in the world, and it's making great strides in that direction.  However, it's still written by and mostly for programmers, so often the easiest way to install and upgrade it is from the UNIX command line!  Many people prefer to use drush, but here's how I do it without drush.  These instructions are for Drupal 7.

To install Drupal on the command line:

  1. in a Web browser, go to http://drupal.org/project/Drupal+project , right-click the Download link for the version you want, and copy the link location.
  2. In an SSH (or Telnet) session to your host account, type
    cd www
    to go to your document root.  (Note: your document root may be called something else, like public_html.)
  3. Type
    wget 
    and paste the link location from step 1, then press Enter.  The file will download to your account, for example drupal-6.9.tar.gz.  "wget" means "get from the Web."
  4. Type
    tar -xzf drupal-7.12.tar.gz
    (or whatever the file name was from step 3) to expand the file into a directory, in this case drupal-7.12.  Think of "-xzf" as standing for "extract zip file."  Think of "tar" as what you use to stick a bunch of files together! (or, in this case, unstick them)
  5. At this point many people would rename the directory to something nicer, like drupal.  I recommend instead making a symbolic link (shortcut) to it, like so:
    ln -s drupal-7.12 drupal
    so that you can keep multiple versions in your account at once without getting confused as to which is which.  "ln -s" stands for "link symbolically"
  6. It is now safe to delete the file you downloaded, like so:
    rm drupal-7.12.tar.gz
    "rm" stands for "remove."
  7. Go to your new URL in a Web browser and follow the directions there.

To upgrade Drupal on the command line:

  1. Log onto your Drupal site with the admin account.  You will need to be admin in order to run the update.php script below.
  2. Follow steps 1-4 above to get the most recent version and expand it.
  3. Back up your database to a file.  If you are using the Backup & Migrate module, this means clicking on Configuration in your black administrative toolbar, clicking Backup & Migrate, and then Backup Now.
  4. Copy the .htaccess and php.ini files from your existing installation to your new one.  Depending on how your site was set up, you may not have these files, but the sites I set up do have them.
    cp drupal-7.9/.htaccess drupal-7.12
    cp drupal-7.9/php.ini drupal-7.12

    cp drupal-7.9/.gitignore drupal-7/12
    "cp" means copy.
  5. Copy the sites directory from your existing installation into your new one:
    cp -R drupal-7.9/sites drupal-7.12
    assuming 6.8 is your existing installation and 6.9 is the new one.  "cp -R" stands for "copy recursively," that is, including the contents of all subdirectories.  If you have not put all of your site's files in the sites directory, you may have to repeat this step for files, modules, themes, etc.  It is a very good practice to always put all of your site's files in the sites directory for this reason.
  6. Redirect the symbolic link to point to the new version, like so:
  7. rm drupal; ln -s drupal-7.12 drupal
    assuming drupal is the symbolic link you created in step 5 above and drupal-7.12 is the new directory you want it to point to.  The semicolon between the two commands prevents any delay between removing the old link and creating the new one.
  8. Go to the status report by clicking on Reports in the black administrative toolbar, then Status Report.  Chances are this will now tell you to update the database and provide you with a handy link to do that.  This is a very important step!
  9. Test your site to make sure it is running correctly.  If you don't see any problems in a day or two, proceed.
  10. Delete your old installation.  Because some of the files are write-protected, this takes two commands:
    chmod -R u+w drupal-7.9
    rm -R drupal-7.9
    "chmod u+w" means "change the modifiers so that the user can write."  "-R" in both case means "recursive," that is, including all subdirectories.