DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Esnare Maussa
Esnare Maussa

Posted on • Updated on

Upgrading from Drupal 8 to Drupal 9 with Composer

Alt Text
Drupal 9 is the new flagship of the popular Framework which was released on June 3, 2020 and it's ready to be used for Production sites.

Here are the main Drupal 9 features:

And many other tools for developers to play with:

Drupal 8.9

Drupal 8.9 was released alongside with Drupal 9, this release includes the same features coming in Drupal 9 with the addition of having backward compatibility for public APIs.

This version is also the end of the Drupal 8 era as there won't be any more updates after this. Therefore, there won't be an 8.10 version coming anytime soon.

8.9 will be maintained until November 2021 and it's a great place to start the process of moving your current website to Drupal 9.

Upgrading to 8.9 will ensure maximum compatibility and the smallest necessary changes for the Drupal 9 update.

Drupal 9 and Composer

If you have been using composer to build your Drupal 8 website, you have been probably using drupal-composer/drupal-project.

Now Drupal 9 comes with an official template called drupal/recommended-project.

With this, you should be able to spin off new Drupal sites with the following command:

composer create-project drupal/recommended-project my-project 
Enter fullscreen mode Exit fullscreen mode

Let's start upgrading from D8 to D9

Before attempt to upgrade your site to Drupal 9, you should update your Drupal 8 to the 8.9 version.

As said before, Upgrading to 8.9 will ensure maximum compatibility and the smallest necessary changes for the Drupal 9 update.

Upgrade Status module

This is a module from the community that tells you what modules need to be updated/patch, what line is the issue and - most of the time - hot to fix it.

This a great module which works for custom and contrib projects.

https://www.drupal.org/project/upgrade_status

This is the step where you will probably spend most of the time as you will have to make sure your current Drupal 8 website is compatible with the Drupal codebase.

Upgrading to Drupal 9 (core) using Composer

Composer is the preferred way of moving forward to work with Drupal 9.

You will have to make sure all the libraries and modules installed on your current site are Drupal 9 compatible. Otherwise, you will get a lot of errors on the terminal thrown by Composer.

Run the following commands to get started with the process:

  • Remove the drupal/core entry in your composer.json file if you have it.

  • Change access permissions for the default folder and the files inside of it:

chmod 777 web/sites/default
find web/sites/default -name "*settings.php" -exec chmod 777 {} \;
find web/sites/default -name "*services.yml" -exec chmod 777 {} \;
Enter fullscreen mode Exit fullscreen mode
  • Pull Drupal 9 and dev dependencies packages:
composer require drupal/core-recommended:^9.0.0 drupal/core-composer-scaffold:^9.0.0 drupal/core-project-message:^9.0.0 --update-with-dependencies --no-update
# If you have drupal/core-dev installed.
composer require drupal/core-dev:^9.0.0 --dev --update-with-dependencies --no-update
Enter fullscreen mode Exit fullscreen mode
  • Update your local code:
composer update
Enter fullscreen mode Exit fullscreen mode
  • Run database updates:
#Drush
drush updatedb

#Drupal console
drupal update:execute
Enter fullscreen mode Exit fullscreen mode
  • Restoring default permissions:
chmod 755 web/sites/default
find web/sites/default -name "*settings.php" -exec chmod 644 {} \;
find web/sites/default -name "*services.yml" -exec chmod 644 {} \;
Enter fullscreen mode Exit fullscreen mode
  • And voila! Check that your site is up and running, run your tests - if that is your thing - and any custom functionality you have on your site.

The above steps are coming from the Drupal Community
https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-8-to-drupal-9-or-higher

Final Thoughts

The Drupal community promised that upgrading to Drupal 9 will be easier than the previous versions and they hold their end of the bargain. Nevertheless, this is only true if:

  • Your website has been upgraded to each Drupal minor versions over the years.
  • All custom/contrib modules are Drupal 9 compatible.
  • Your custom/contrib themes are compatible with Twig 2.

Top comments (1)

Collapse
skozeniuk profile image
SashaKozeniuk

Thanks for your ideas! I read this article and heard a lot about Drupal online certification, what do you think about it?

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.