Upgrade Drupal by using a patch file

By gill, 15 June, 2016
From drupal.org Last updated August 27, 2012. Created on January 15, 2009. Edited by fuerst, lukas.fischer, adellefrank, rezboom.

The standard procedure to upgrade Drupal to the latest release is to download it from drupal.org and follow the included UPGRADE.txt. For administrators using the UNIX shell, it may be easier by using a patch file instead. To follow the procedure described below you need the diff and patch commands which are available at most LINUX distributions.

  1. Backup everything (as instructed in UPGRADE.txt) If applying the patch fails, you want it to be easy to restore your site. Aside from the VERY IMPORTANT database, you also need to back up the following, if you have customized them:
    • .htaccess file
    • robots.txt file
    • settings.php file (sites/all/default or sites/all/example.com)
    • custom profiles (profiles)
    • custom themes (sites/all/themes)
    • custom modules (sites/all/modules/custom)
    • contributed modules (sites/all/modules/contrib)
    • custom features (sites/all/modules/features)
  2. Create the patch file
  3. Instead of creating the patch file by yourself you may download patch files for the 5.x, 6.x, and 7.x Drupal series from drupal-upgrade-easier.
  4. Download the latest Drupal release from the Drupal Download page (like version 6.9, called latest below)
  5. Download the Drupal release matching your installation by modifying the download URL for the latest release (like version 6.4, called current below). Get version information about your current Drupal installation from the CHANGELOG.txt inside your Drupal root.
  6. Untar both tar files and run the shell command
    • diff -Naur drupal-current drupal-latest > drupal-current-to-drupal-latest.patch
  7. Move the created patch file into the root of your current Drupal installation
  8. To prepare the upgrade follow UPGRADING.txt up to "5. Remove all of the old files and directories from the Drupal installation directory." After that, continue using the Patching commands listed below.
  9. Patching cd to your current Drupal installation directory
  10. Test drive the patch by running the shell command
    • patch -p1 --dry-run < drupal-current-to-drupal-latest.patch
  11. You may see a lot of lines like patching file includes/bootstrap.inc telling you which files will be patched. WARNING: Don't proceed if you see error messages like Reversed (or previously applied) patch detected or 1 out of 2 hunks FAILED. Your Drupal installation probably is modified somehow and the patch file will not apply completely. You now better switch to the standard upgrade procedure described in UPGRADE.txt.
  12. Finally apply the patch file by running
    • patch -p1 < drupal-current-to-drupal-latest.patch
  13. Proceed with UPGRADING.txt from 8. Verify the new configuration file to make sure it has the latest and correct information (sites/default/settings.php) and run update.php. Faster procedure but may be dangerous!
  14. On my Drupal installations, I usually only apply the patch file after doing a backup of the complete Drupal directory and its database(s) and run update.php for every site afterwards. This never put me in trouble but your mileage may vary.