Upgrading your Drupal 8 base system easily

botond published 2018/09/08, Sat - 04:52 time

Content

 

Introductory

The newer Drupal 8 base system update package released recently will be available for today's description, which will update the Drupal 8 Our CMS system.

Upgrading the base system can be done on any Drupal 8 based website, I in this description a Debian 8 is the perfect server earlier with Debian 8 installed I'll do it. Accordingly, the next uploaded server version will already include this update.

 

Update (2021-02-25):
The upgrade guide for the Drupal 9 base system has also been completed:

 

 

Upgrade notification

When Drupal releases another base system update package, our website will automatically notify you and email you with an update. Then when you enter the admin menu of the page a Expansion main menu, you will also see a notification that another basic system update is available:

Drupal 8 Base System Update - Update Notification

If you follow the link in the notification panel, we'll get more information about the update:

Upgrading Drupal 8 Base System - Manual upgrade required

This page shows you when you last checked for available updates and that it is not a module upgrade, which can be updated with a few clicks, but rather a basic system upgrade, which is a bit more complicated. And we can see the list with just one item now: Drupal core, and that we have a newer version of 8.5.6, 8.6.0. Here if we click on the Release Information link will take you to the Drupal English page where you can see the full details of the update package.

Right now we are faced with a rare case that 2018. On September 5, two versions were released simultaneously, the 8.5.7 and the 8.6.0. The 8.5.7 version contains minor patches here, and the 8.6.0 description describes it as the first version of Drupal 8 that fully supports Drupal 7 migration. So this is more than minor bug fixes. Obviously, we're going to post this update for 8.6.0, as the system has recommended it to us. About this version yet read more herewhat's new.

Alright so far, but how do we start upgrading him?

If we go to Drupal upgrade documentation page, we first find ourselves in a maze where they offer us several solutions at once:

So, for those who are first in the process of upgrading the Drupal 8 base system, this variety of upgrade methods can be a puzzle. I have tried all of them at the beginning, but I had problems with them, they were macerated, in some cases the update failed, because I added several modules with Composer, after which I have to upgrade differently, etc. So over time, my own method came up, which I use for updates.

In this description, I present my own best practice that allows you to perform the upgrade easily, conveniently, quickly, and with minimal downtime. My method works a bit on all three of the above options, but it works reliably.

The description may seem longer than the actual build, because here I will go into detail on more of what we may encounter during the upgrade.

 

 

Prerequisites

Each method has basic conditions without which we can't perform the update, my method also has some, here I collect them so that you don't have to rush after anything during the update. These only need to be obtained / installed once, and once they are available, the upgrade itself becomes very simple, so it pays off in the long run.

Terminal, SSH access

Since the main topic of this page is command line (CLI) solutions, so we will still need them SSH access, which is already a standard part of today's web hosting service. If you do not operate the server / hosting yourself, but subscribe to a hosting service, you may need to ask your operator for SSH access. But in this case, it is worthwhile to look around at the service you received web hosting control panel, because chances are, for example, that an SSH access icon is sitting there in a cPanel.

The upgrade is done so that you do not need root privileges, but only basic user access to the storage, so it will work in the most common cases.

Composer PHP package manager

For those who are not yet familiar with the Composer PHP package manager, you may want to run through one of it short description, and the installation guide. All you need to know here is that this guide shows you how to install Composer in global mode with root privileges, but since I wrote above that you won't need root privileges here, you can install it locally in any directory on your repository. It is advisable to put it in the path so that we can use it comfortably.

Go

A Git version control system is not part of the Debian base system, but is usually installed in web hosting environments. If it is still not available from the command line, ask your system administrator to install it. If you run the server yourself, install the following apt-get command:

sudo apt-get install git

Drush

A Drush the Shell of the Drupal system, with which we can manage the whole system from the command line. In a terminal, go to the main directory of your Drupal system and issue the following command:

composer require drush/drush

 

Preparations before upgrade

Backup

Always make a backup of your entire website and database before upgrading. For more information, see another description.

Download and unpack the update package

Then the From the Drupal upgrade package page save the tar.gz link of the appropriate version to the clipboard and download the wget command to a subdirectory of our webhost where we unpack it. Go to the main directory of your webhost and then do the following:

mkdir tmp
cd tmp
wget https://ftp.drupal.org/files/projects/drupal-8.6.0.tar.gz
tar -xvzf drupal-8.6.0.tar.gz
cd drupal-8.6.0/

Of course, work with the current version numbers, which is the most recent.

Examining file discrepancies

Please read the documentation for the update package carefully to see what has been changed. Pay attention to the following changes to the following files:

  • composer.json
  • .htaccess
  • sites / default / settings.php

These are the three files that you usually change during the operation of the website, so you should watch out for them. Of course, we look at the other files in the main directory, but they are not customized by the webmasters, so if they are changed, they will need to be copied in the copy section below.

When one of them is modified, the user is informed in the description. I'm still sure, on a secure basis, I first compare the files in the new update package to the ones in the previous version of the update package to rule out their modification (modification date, exact file size). If there is no difference between them, there is nothing to do with them. Fortunately, this is the most common case.

Very rarely, when a file has been modified in the service pack, we need to be aware that if we have modified something in the file while operating the website, it should be combed with the changes in the service pack.

For example, the prerequisites have already changed our composer.json file when we installed Drush. Or, for example, when we installed Drupal, we changed the settings.php file when we set up the trusted hosts section...

So we have to pay attention to things like that. Fortunately, this is a very rare case, but in this case, you need to repackage your own changes to the appropriate files in the unpacked service pack, and then copy everything at once during the copy phase to copy everything in one step at the time of the update.

 

 

Upgrading the Drupal 8 Base System

If we are all up to now, then upgrading the Drupal 8 base system is now a child's play.

Maintenance mode

The page must be switched to maintenance mode so that there is no interruption during the upgrade process. In this mode, visitors will see a preset text and temporarily will not have access to the rest of the page.

We could have done this before, but for a live page, it would be more disruptive if we redeployed the page too early, as there hasn't been any intervention on the page yet. So now enter the admin, inside the Configuration main menu and below the Maintenance mode submenu. This page will welcome us:

Upgrading Drupal 8 Base System - Maintenance Mode

 

Mark the Use the site in maintenance mode section and save the form.

Delete and copy Core and Vendor directories

From this point on, the page is not accessible to visitors, so don't waste time, but go to the terminal's main directory and delete the core / and vendor / directories:

rm -rf core/
rm -rf vendor/

Then we replace these two directories from the update package:

cp -r tmp/drupal-8.6.0/core/ .
cp -r tmp/drupal-8.6.0/vendor/ .

Copying different files (optional)

If there were different files when examining the file differences, and you have merged the differences in the files included in the installation package, copy those files and overwrite the existing ones with them.

Update your system with Composer

Run the composer update:

composer install

It does everything from examining dependencies to downloading new system packages. Then update the database with Drush and rebuild the cache:

vendor/bin/drush updatedb
vendor/bin/drush cr

During the upgrade you can ask questions, type yes there and then enter.

 

The big advantage of the Drush update over the browser update (update.php) is that if there is a snag, such as a malfunctioning module cracking from the new base version, we will get an Internal Server Error message in the browser, and worse than that more on a page that can be extremely annoying and we don't even know the cause of the error, we can at most bug the log files. And, when updating with Drush, if anything goes wrong, it prints out in enough detail, which we can probably fix.

 

Turn off maintenance mode

Finally, uncheck the maintenance mode in your browser and save the form again.

You are now ready to upgrade your base system, and the page will be available again.

 

 

Conclusion

Despite the length of the description, it can be seen that the point between the maintenance mode on and off happened very quickly, thus minimizing the downtime of the website. In practice, this is very important, as we may lose visitors during the downtime, and search engines may temporarily drop their rankings if they are unable to index the pages for an extended period of time. This in turn leads to further loss of visitors.

This is why it is advisable to do all the other fake parts before the maintenance mode, such as checking for prerequisites, downloading and unpacking the update package, doing file comparisons, etc., because the page is not available until then, so we have plenty of time, no need to rush anything. And the actual update itself - with a proper routine - will take place in about 1 minute.

It is also worth doing all this at night, when the website traffic is usually low.

Of course, with a fresh Drupal installation, there are hardly any visitors when you first practice this. Here, I just wanted to illustrate that this already matters for a higher-traffic site. But by then, it's all a matter of routine.