As a brief “note to self,” this is how I just updated a Drupal 7 website using Drush. Please note that the output of some of the commands below refer to early versions of Drupal 8, but these commands also work with Drupal 7.
First, do these things:
- Backup the Drupal 7 database and files
- Backup the site-specific files
- .htaccess
- robots.txt
- sites/default/settings.php
Then run these commands:
drush sset system.maintenance_mode 1
drush cr
drush up drupal
drush updb
drush entup
drush sset system.maintenance_mode 0
drush cr
As an important note, I ran these commands using Drush 8. It looks like the commands will be different with Drush 9.
Note 1: I created an alias named
drush8
to run these commands, because they are run with Drush 8.Note 2: In 2020, several of these commands now fail to run properly. Fortunately the “update” commands work.
That’s the short answer of how to update a Drupal 7 website using Drush. If you’re interested in more information, see the notes below. (The notes are cryptic, but hopefully useful.)
Output from the drush “update drupal” command
Here’s the output from running the drush up drupal
command:
$ drush up drupal
Update information last refreshed: July 22, 2017 - 12:00pm
Name Installed Version Proposed version Message
Drupal 8.3.4 8.3.5 Update available
Code updates will be made to drupal core.
WARNING: Updating core will discard any modifications made to Drupal core files,
most noteworthy among these are .htaccess and robots.txt. If you have made any
modifications to these files, please back them up before updating so that you can
re-create your modifications in the updated version of the file.
Note: Updating core can potentially break your site. It is NOT recommended to update
production sites without prior testing.
Do you really want to continue? (y/n): y
Project drupal was updated successfully. Installed version is now 8.3.5.
Backups were saved into the directory /root/drush-backups/.../20170722180058/drupal. [ok]
No database updates required
(Note: Even though it says no database updates are required, I attempted them
to see what would happen.)
$ drush updb
No database updates required [success]
$ drush entup
No entity schema updates required [success]
Cache rebuild complete. [ok]
Finished performing updates.
Notes on the Drupal 7 drush process and commands
Here’s a link to the official Drupal 7 update docs.
Notes related to the overall process:
- To identify what packages can be updated (without changing anything):
drush ups
(aka,drush pm-updatestatus
)
- Clear the caches before running a database backup
drush cr
(ordrush cc all
, if you prefer)
- Put Drupal 7 site into maintenance mode
drush sset system.maintenance_mode 1
- Drupal 7 commands:
drush vset --exact maintenance_mode 1
drush cache-clear all
- Update drupal core
drush up drupal
(same as:drush pm-update drupal
)- note:
drush pm-update
is the same as runningdrush pm-updatecode
and thendrush updatedb
- To update an individual module, such as the Views module:
drush up views
- To only apply security updates:
drush up --security-only
- To apply any required database and entity updates (in theory this isn't needed, because
drush up
should do this)drush updb
# database updatedrush entup
# entity update
- If all is well, put your site back online:
drush sset system.maintenance_mode 0
drush cr
- Drupal 7 commands
drush vset --exact maintenance_mode 0
drush cache-clear all
In addition to updating Drupal core, I also ran these commands to update the Drupal modules shown:
drush sset system.maintenance_mode 1
drush cr
drush up login_security
drush up metatag
drush up mollom
drush up similarterms
drush up token
drush updb
drush sset system.maintenance_mode 0
drush cr
Other drush commands
To get an overview of your Drupal website, using drush status
:
$ drush status
Drupal version : 8.3.4
Site URI : http://default
Database driver : mysql
Database hostname : localhost
Database port : 3306
Database username : omitted
Database name : omitted
Drupal bootstrap : Successful
Drupal user :
Default theme : omitted
Administration theme : omitted
PHP configuration : omitted
PHP OS : Linux
Drush script : /usr/local/bin/drush
Drush version : 8.1.2
Drush temp directory : omitted
Drush configuration :
Drush alias files :
Install profile : standard
Drupal root : omitted
Drupal Settings File : sites/default/omitted
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : omitted
Sync config path : sites/default/files/omitted
To identify what packages/modules can be updated, without making any changes (query only), use drush pm-updatestatus
, or its alias, drush ups
:
$ drush ups
Checking available update data ... [ok]
Checking available update data for Drupal. [ok]
Checking available update data for AddToAny (addtoany). [ok]
Checking available update data for Login Security (login_security). [ok]
Checking available update data for Metatag (metatag). [ok]
Checking available update data for Mollom (mollom). [ok]
Checking available update data for PHP Filter (php). [ok]
Checking available update data for Similar By Terms (similarterms). [ok]
Checking available update data for SMTP Authentication Support (smtp). [ok]
Checking available update data for TOC API (toc_api). [ok]
Checking available update data for TOC filter (toc_filter). [ok]
Checking available update data for Token (token). [ok]
Name Installed Propose Message
Version d
version
Drupal 8.3.4 8.3.5 Update available
Login Security (login_security) 8.x-1.0 8.x-1.2 Update available
Metatag (metatag) 8.x-1.0-beta9 8.x-1.1 Update available
Mollom (mollom) 8.x-1.1 8.x-1.2 Update available
Similar By Terms (similarterms) 8.x-1.2 8.x-1.3 Update available
Token (token) 8.x-1.0-alpha2 8.x-1.0 Update available
If for some reason you want a list of all available extensions, including modules and themes:
drush pm-list
drush pml
Clear the caches:
drush cr
drush cc all
To enable/disable modules:
drush pm-enable project_name
drush pm-disable project_name
Drush help:
drush help
drush topic
See also
- https://www.drupal.org/docs/8/update/update-procedure-in-drupal-8
- https://drushcommands.com/
- https://www.drupal.org/docs/7/update/updating-modules
- https://www.drupal.org/docs/7/update/updating-drupal-using-drush
- https://www.digitalocean.com/community/tutorials/a-beginner-s-guide-to-drush-the-drupal-shell