Installing and Upgrading Drupal and its Modules 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.  However, so far it's written by and for programmers, so often the easiest way to install and upgrade it is from the UNIX command line!  Here's how to do it:

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-6.9.tar.gz
    (or whatever the file name was from step 3) to expand the file into a directory, in this case drupal-6.9.  Think of "-xzf" as standing for "extract zip file."  Think of "tar" as what you use to stick a bunch of files together!
  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-6.9 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-6.9.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. Copy the sites directory from your existing installation into your new one:
    cp -R drupal-6.8/sites drupal-6.9
    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.
  4. Back up your database to a file, like so:
    mysql -u username -p databasename > drupal-6.8.sql
    where username and databasename are your database name and username, and 6.8 is your existing version.  This will take the contents of databasename and save them to a file called drupal-6.8.sql.
  5. Redirect the symbolic link to point to the new version, like so:
    rm drupal; ln -s drupal-6.9 drupal
    assuming drupal is the symbolic link you created in step 5 above and drupal-6.9 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.
  6. Run the update.php script, which will be at http://www.yoursite.com/drupal/update.php (where yoursite.com is your domain name).
  7. Test your site to make sure it is running correctly.  If you don't see any problems in a day or two, proceed.
  8. Make a compressed backup of your old installation, like so:
    tar -czf drupal-6.8.tar.gz drupal-6.8
    (where drupal-6.8 is your old version)  Think of "-czf" as standing for "create zip file."
  9. Delete your old installation.  Because some of the files are write-protected, this takes two commands:
    chmod -R u+w drupal-6.8
    rm -R drupal-6.8

    "chmod u+w" means "change the modifiers so that the user can write."  "-R" in both case means "recursive," that is, including all subdirectories.

To install a module or theme on the command line:

  1. in a Web browser, go to the module's page at drupal.org , 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/drupal/sites/all/modules
    to go to your modules directory.  (Note: do not put modules in the drupal/modules directory -- that's only for core modules!)  Themes go in www/drupal/sites/all/themes instead.
  3. Type
    wget 
    and paste the link location from step 1, then press Enter.  The file will download to your account, for example views-6.x-2.2.tar.gz .
  4. Type
    tar -xzf views-6.x-2.2.tar.gz
    (or whatever the file name was from step 3) to expand the file into a directory, in this case views.
  5. It is now safe to delete the file you downloaded, like so:
    rm views-6.x-2.2.tar.gz
  6. Go to your admin/build/modules page in a Web browser and enable the module.  Or admin/build/themes for a theme.

To upgrade a module or theme on the command line:

  1. Follow steps 1-3 above to download the file to the proper directory.
  2. Make a backup of the existing module, like so:
    tar -czf views-6.x-2.1.tar.gz views
    where views is the module and 6.x-2.1 is the version you are currently using.  You may also want to back up your database by following step 4 of the "upgrade Drupal" instructions above.
  3. Type
    tar -xzf views-6.x-2.2.tar.gz --overwrite
    (or whatever the file name of the file was) to expand the file into the existing module or theme's directory, in this case views, overwriting any files that already exist.
  4. It is now safe to delete the file you downloaded, like so:
    rm views-6.x-2.2.tar.gz
  5. Run the update.php script, which will be at http://www.yoursite.com/drupal/update.php (where yoursite.com is your domain name).
  6. Go to admin/by-module on your site and check the settings for the module you just upgraded, in case they have changed.