Update Core in Drupal

Published Dec 1, 2020
Updated Mar 31, 2023
By Simon

Drupal 9 doesn't have automatic update yet for core but it is coming. Check the bottom of the page for more information on automated updates. That said don't let that stop you from using Drupal as a CMS as it just gets better with each version and it isn't that difficult to update once you have a system in place.

A note on ongoing development and why it is needed. Since all technologies are moving forward it is important to keep moving forward with it otherwise you will need to do a full rebuild in a few years which will in fact cost more. I will write more about this but Drupal uses other PHP frameworks and libraries and is built on PHP so it has to keep up with the whole PHP landscape.

Okay with the housekeeping out of the way we first need to check for updates for your Drupal instance.

Checking For Updates

We can check for updates using the UI fairly easily. Visit the Status Report and Updates pages. If you have your site set up correctly you can have automated emails sent to you when new updates are available aswell.

Below are some pages you should get familiar with to overview your site's status and updates.

Status Report: Full site overview gives you a high-level overview of your site, it can be found at the below path.
/admin/reports/status

Available updates: Nicely presented page colour-coded for updates needed.
/admin/reports/updates

Update: Displays needed updates and enables one-click UI updates for modules.
/admin/reports/updates/update

Once you know your site needs updating you need to prepare it.

Preparation

You will need to login into your sites hosting account and be in the directory that your Drupal site that needs updating is in.

Make a backup

tar -cvf my-drupal-site_todays-date-BU.tar my-drupal-site

or use archive in cPanel if you use cPanel.

Backup database

By far the easiest way to Back up your site's database is to use Backup and Migrate, if you have it installed visit the modules page and back up your database. See Backup and Migrate Module for more details. You can also use MySQL dump or a UI such phpMyAdmin. Whatever your choice is don't forget this step.

Put the site offline

You can easily put the site into maintenance mode using the UI of Drupal, visit the Maintenance mode page.

Administration > Configuration > Development > Maintenance mode
/admin/config/development/maintenance

Or you can use Drush if you are using shell and have installed Drush.

drush state:set system.maintenance_mode 1

What is Drush?
It is Drupal Shell, DrupalShell, Drush. Drush needs to be set up and the path needs to be set up.  To learn more about Drush I wrote a Drush quick start guide. Check the post to see up Drush then run the above command.

Manual Updates of Drupal

You will need access to the server either using cPanel, an FTP Client file browser, or shell access.

If you need an update check the release page, these are given to you on the Update pages mentioned above. Below is the Drupal releases page and the release page for 9.0.7

https://www.drupal.org/project/drupal/releases
https://www.drupal.org/project/drupal/releases/9.0.7

Download the file and upload it to the directory that your instance is in.

Or copy the link location which looks like this https://ftp.drupal.org/files/projects/drupal-9.0.7.tar.gz and use wget to download the file and then extract the content first using gunzip and tar -xvf

Replace the drupal-9.0.7.tar.gz with the correct release.

wget https://ftp.drupal.org/files/projects/drupal-9.0.7.tar.gz
gunzip drupal-9.0.7.tar.gz #gunzip may not be needed, try without first
tar -xvf drupal-9.0.7.tar

Delete all the files and directories that come with Drupal core, what we are doing is replacing every file from the new release archive, in most cases most of the files will be the same. If you check the release notes you can see what files have been updated and what issues they fixed.

cd into the root directory of the Drupal instance you are updating and run the below commands.

rm -rf core vendor
rm -f *.* .[a-z]*

Now we need to copy the files from the new release into the root of your Drupal site. cd into the release directory.

cp -R core vendor /var/www/example.com/public_html/my-drupal-site
cp -R *.* .[a-z]* /var/www/example.com/public_html/my-drupal-site

Check for changes to .htacess, settings.php, robots etc. and replace if needed, this will be noted on the release page.

Run update.php by visiting the page logged in or by running the Drush commands, then put your site online and flush the cache.

drush updatedb:status
drush updatedb
drush cache:rebuild

For more information, you can check https://www.drupal.org/docs/updating-drupal/updating-drupal-core-manual…

Composer Updates

It is assumed your site is off-line, if not go back and check the top of the page put the site offline or if are using Drush you can use the below command.

drush state:set system.maintenance_mode 1

Using composer we can check for outdated modules using show and the -o flag, plus we can stipulate just Drupal packages by passing drupal as the vendor and * to show all Drupal packages like so

composer show -o "drupal/*"

Output

drupal/admin_toolbar    2.3.0     2.4.0     Provides a drop-down menu interface to the core Drupal Toolbar.
drupal/backup_migrate   5.0.0-rc1 5.0.0-rc2 Backup and Migrate Drupal Module
drupal/core             9.0.6     9.0.8     Drupal is an open source content management platform powering millions of websites and applic...
drupal/core-recommended 9.0.6     9.0.8     Locked core dependencies; require this project INSTEAD OF drupal/core.

To update a Drupal install set up using core-recommend run the below command, core-recommend is the official recommended profile.

composer update "drupal/core-*" --with-all-dependencies

# update article 2023 to use the above
# composer update drupal/core-recommended --with-dependencies 

Using  composer update "drupal/core-*" --with-all-dependencies you may not get the message Nothing to install or update. However, if you do please read on.
If this doesn't work and you get Nothing to install or update you may need to run composer require.
The command will sometimes only update dependencies and if that is the case you will need to use composer require.

Sites I have upgraded from Drupal 8 seem to face this issue, it's not really an issue though, use the following command.

composer require drupal/core-recommended:^9.0.0 --update-with-all-dependencies

After running composer update successfully you will get the message that it was a success and the composer.json lock file is updated.

Then all we needed to is check for database updates, run the updates, put your site online and then rebuild the cache.

drush updatedb:status
drush updatedb
drush state:set system.maintenance_mode 0
drush cache:rebuild

You should get no output if now check for outdated again.

composer show -o "drupal/*"

So that's it, not difficult to update Drupal at all and spending the time to get familiar with the command line will be beneficial and setting up Composer and Drush makes it an even faster process so I definitely recommend that. That said cPanel or shell access and manual no composer updates are really only a few more lines of commands or clicks.

The most important thing is, do back up and test the updates on a staging site first. If you need help setting up a site or updating a site be sure to get in contact.

Tags