Drupal 8 User Guide: 13.5. Updating the Core Software
Articles,  Blog

Drupal 8 User Guide: 13.5. Updating the Core Software


Updating the Core Software
with Joe Shindelar This tutorial covers
how to update the core software using the administrative interface
or with Drush. By the end of this tutorial, you’ll know how to update
the core software, either through
the administrative interface, or by using Drush commands. If you want to use Drush
to perform the update, you’ll need to make sure
that Drush is installed first. It’s also a good idea
to test this process on a development version
of your site. If you haven’t already, now would be a good time to create
a development version of your site. See the written version of this tutorial for links to each of the prerequisites. At a high level,
the steps involved are as follows: 1. Make a backup,
just in case anything goes wrong. 2. Put your site into maintenance mode 3. Update the core software’s code
to the latest version 4. Run the database update script 5. Take the site out
of maintenance mode, and, 6. Clear the cache for good measure Let’s walk through an example. First, make a complete backup
of your site. In this case, I’ve made a backup
using the mysqldump command, and created this sql.gz file, which is all of the database
content for my site, as well as a .zip of the directory
that contains all of the code that I’m going to be updating
and replacing. In order for these updates to work, you’ll need to be either
logged in as a user with the Administer software
updates permission or you can open the settings.php file
under sites>default>settings.php. In the settings.php file, scroll down until you find the line, $settings [ ‘update_free_access’ ] like so, which, for security reasons,
is set to FALSE by default. As needed, you can temporarily
change the setting to TRUE, which overrides the need to be
logged in when performing updates.
I can change that here. The next thing that you’ll want to
consider is temporarily disabling any caching technique
your application might be using, like Varnish or Memcache, just to ensure that they don’t get in
the way while performing an update. Then, put your site in maintenance mode. That can be done
by clicking on Configuration, and then under
Development>Maintenance mode, and checking the box
for Put site into maintenance mode, and clicking Save configuration. The next step is to download
the updated code. At this point,
you’ve got to make a decision. If you’re managing
your site’s files with Composer, you’ll want to use Composer
to get the updated files. This is covered in another tutorial. Otherwise, you can download the
code from Drupal.org and place it manually, or you can
download it using Drush. To download it from Drupal.org,
navigate to Drupal.org, and then click Download & Extend, select the current version
of Drupal core, and then click to download
either the tar.gz or the .zip file for the latest version. Once you’ve done that, you can
extract it into a temporary directory, and then you need to copy
all of the appropriate files from this new code
that you just downloaded over the code that currently
makes up your site. Let’s go ahead and do that. Be aware of hidden files. Things like the .htaccess file that comes with Drupal core
are important to update as well. I’ll start by first removing the code from my existing site
that I no longer need, which is everything
that I haven’t customized. In this case, that’s all the files
and folders excluding the modules, sites, and themes directory. I’ll leave those as is because
they contain my customizations. I can come over here
and grab all of the updated code, except for the modules, sites, and themes directory. And then I can come over here,
in the code that I just downloaded, and grab all the updated files, except the ones that I don’t need modules, sites, and themes, and place those into my directory
here of my existing site. Basically, just updating all of the code with the latest version. Alternatively, you can use Drush
to download the archive and extract it in one step. You can do so by navigating
to a temporary directory and then running the
drush dl drupal command. Once Drush has completed
downloading the files, the process is the same. You locate all of the files
that you have not customized, and move those over to your site’s code, replacing the existing files. Either way, whether you download the files
manually and extract the .zip file, or download them with Drush, once you’ve completed
that step of updating the code, you need to run
the database update script. Note that if you use Composer
to manage your files, you’ll pick back up here
in the update process. You can run the updates
in 1 of 2 ways, either by vising the update.php script
in your browser. Once there, you can click
the Continue button. It’ll list any pending database
updates that you could review if you would like, and then click
Apply pending updates. Once completed, you’ll get a list
of all of the successful updates. If you get any errors or warnings, you can re-run the update script again, until all of the updates
have been completed successfully. Alternatively, if you’re using Drush, you could run the
drush updb command, which will do the same thing,
run the database update scripts. Once that’s complete, if you changed the settings.php
file earlier, you’ll need to revert that now. Open settings.php in your editor and change the update_free_access
line back from TRUE to FALSE. Then, back on your site, you can take your site out
of maintenance mode Click on Administration pages, it takes you back to your site. You’ll see the message here that
you’re operating in maintenance mode.
You can click Go online, take the site out of maintenance mode. And finally, to verify that it worked, you can navigate to Reports,
and then Status Report, and confirm that you’re running the
latest version of the core software. In this tutorial, we learned how to upgrade
the core code after a security update, either manually or via Drush, as well as how to run
the database update script in order to keep our site
up-to-date and secure.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *