The whys and hows of your easiest upgrade to Drupal 9

04 May 2021

Several years ago we were all happy to discover the great news about the upcoming Drupal 9 that promised to be super easy to upgrade to. Finally, the ninth version of the CMS was released in June, 2020. Now that it has almost been a year after the release, there is a growing number of websites that have already made this easiest upgrade in history.

The key part of the Drupal 9 upgrade is getting your website ready based on a number of requirements. Today, we will review how to prepare and how to actually perform your Drupal 8 to Drupal 9 upgrade. However, before that, we will make a little introduction about how D9 is doing and what its key features are that make it increasingly popular.

Drupal 9: time to upgrade!

The latest statistics show the record-breaking popularity of D9. Dries Buytaert summed up his keynote speech at DrupalCon North America 2021 in his State of Drupal presentation of April 2021. According to this information, it only took one month to jump from 0 to 60,000 websites on D9. For comparison, it took three months to reach the same milestone for D7 to D8 upgrades.

This presentation says that contributed modules are also getting more prepared for D9. One and a half years ago, only one-third of the top 50 modules were ready for it and today their share is 90%! This means that more websites that are using the most popular add-on community-created modules can upgrade to Drupal 9 in a hassle-free way.

What’s new in Drupal 9: key improvements

In D9, we do not expect ground-breaking changes from the start. It is not a rebuild of the core as was the case with Drupal 8. On the contrary, D9 is built on D8’s codebase. D9.0 is almost the same as D8.9 released on the same day but with dependencies updated and deprecations removed.

Developers are working on ambitious enhancements for D9 throughout its development to make it more user-friendly, more open to other digital channels, more accessible, etc. Still, there are several improvements we can see in it right now:

  • D9 starts an era of easy upgrades. They are nothing to compare with tedious D7 to D8 upgrades that used to take almost the time of a rebuild from scratch. D9 is backwards compatible with the latest release of D8 and the efforts needed for an upgrade are really minor.
  • Modern versions of third-party components inside D9 are bound to make websites faster, D9 supports:
    • Symfony 4.4 (with future plans for Symfony 5 and even 6 that is yet to be released)
    • Twig 2
    • CKEditor 4.1 (with future plans for CKEditor 5)
  • The use of the latest PHP improves website performance, adds security, and makes the work of development and support teams more efficient. As of Drupal 9.1, we see the official and full compatibility with the new PHP 8.
  • The new default front-end theme named Olivero is outstanding for its high level of accessibility (WCAG AA conformance), modern design, support for the latest core functionality, and much more.

How to prepare for a Drupal 9 upgrade

Here are the key steps in getting a D8 website ready for D9:

1. Updating the core

It all begins with updating your D8 core to version 8.8 or 8.9. These releases introduce API compatibility, bug fixes, database optimization, and more, for D9 readiness. It is recommended to update the core using the Composer dependency manager.

2. Updating the contributed modules and themes

Contributed modules are to be updated by their maintainers, and you will need to install their updated versions while checking on the module’s page if it is ready for Drupal 9.

For most of the popular modules, there will be no problem with D9 readiness. There is also a D9 Deprecation Status page by Acquia that shows the progress of contributed modules in this area. In many cases, the contributed D8 modules do not require a lot of rewriting from their maintainers, just a few lines of deprecated code replaced.

Still, if you really need some contributed module and you see it’s not Drupal 9 compatible and has not been maintained for a while, you can update it yourself or hire developers to do it.

To get the whole picture of which modules on your website need an update, it’s very helpful to analyze the site using tools like the Drupal Check CLI tool. It also has a more user-friendly implementation as a module with a user interface — the Upgrade Status module. These tools check your site for Drupal 9 compatibility and give you update suggestions in a report. It informs you about the status of not just contributed projects, but also the core, the hosting environment, the custom modules, and more. It gives you hints about what to remove, update, additionally scan, collaborate with maintainers about, etc.

3. Removing deprecated code from custom modules and themes

When it comes to custom modules on your website, getting them ready for Drupal 9 is your task. Still, as mentioned above for contributed modules, cleaning them up from deprecated code may be quite easy and just a “find and replace” task.

The report made by Drupal Check/Upgrade Status will also cover your custom modules so you can estimate the needed efforts. Next, there is the Drupal Rector tool that has a contributed module implementation named the Upgrade Rector module. Rector gives you suggestions on automated code fixes and refactoring, as well as performs these fixes. It can relieve you of manual work by automatically renaming the PHP classes, methods, properties, and other elements.

4. Updating PHP on the server

Before upgrading to Drupal 9, check the hosting requirements because there may be a need to update your environment. They are currently as follows:

  • PHP must be no older than version 7.3 for D9. You can also use 7.4. As mentioned earlier, D9.1 already supports PHP 8.
  • If you are using Apache, it must be no older than 2.4.7. If you are using Nginx, it must be no older than 0.7.
  • Your database needs to be 5.7.8+ for MySQL or Percona, 10.3.7+ for MariaDB, 3.26+ for SQLite, and 10 with the pg_trgm extension for PostgreSQL.
  • If you are using Drush, its version must be 10.

How to upgrade from Drupal 8 to Drupal 9

As soon as the preparation requirements are fulfilled, the bulk of the Drupal 9 upgrade work is done. You will now need to run just a couple of Composer commands.

The following instructions assume your project is using Composer and the recommended-project Composer template, not drupal-project (check our Composer article to learn more about switching to the modern template).

You will need to run the Composer commands to get the drupal/core-recommended and drupal/core-composer-scaffold packages.

composer require drupal/core-recommended:^9.1.8drupal/core-composer-scaffold:^9.1.8drupal/core-project-message:^9.1.8--update-with-dependencies --no-update

If you are using the drupal/core-dev dependencies, you will need to updates these as well with this command:

composer require drupal/core-dev:^9.1.8--dev --update-with-dependencies --no-update

Finally, the code will need to get updated with the most important Composer command:

composer update

If everything works as expected, you should see the information in your command-line about updating drupal/core-dev. For more specific details and possible troubleshooting during your upgrade to Drupal 9, you can check out the drupalize.me guide and the drupal.org documentation.

Have a smooth Drupal 9 upgrade!

It’s really great to know that easy Drupal upgrades have become reality, and this advantage will continue with D10 and beyond. Ready for your easiest upgrade ever? Drop a line to Golems and we will take care of every step of your upgrade from Drupal 8 to Drupal 9! If you are using D7, the upgrade process will take longer due to major architectural differences, but it’s definitely worth the effort.

With love for innovation,

Your Golems