Upgrading from Drupal 8 to Drupal 9 with Composer
Tags: drupal9, upgradedrupal, drupal8todrupal9, composer
Published: 2020-06-25 03:26:43

[![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ww9e84kuwvghjsv85jxk.png)](https://www.buymeacoffee.com/Esnare)
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:
- Symfony 4.4
- Twig 2
- CKEditor 4
- PHPUnit out of the box.
- Official composer template [drupal/recommended-project](https://github.com/drupal/recommended-project). 

And many other tools for developers to play with:

- [How Drupal 9 was made and what is included] (https://www.drupal.org/docs/understanding-drupal/how-drupal-9-was-made-and-what-is-included)
- [Which modules have been removed from Drupal 9?](https://www.drupal.org/docs/understanding-drupal/how-drupal-9-is-made-and-what-is-included/which-modules-have-been-removed)

## 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](https://github.com/drupal-composer/drupal-project).

Now Drupal 9 comes with an official template called [drupal/recommended-project](https://github.com/drupal/recommended-project).

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

```bash
composer create-project drupal/recommended-project my-project 
```

## 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](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:
```bash
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 {} \;
```

- Pull Drupal 9 and dev dependencies packages:

```bash
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
```

- Update your local code:
```bash
composer update
```

- Run database updates:
```bash
#Drush
drush updatedb

#Drupal console
drupal update:execute
```

- Restoring default permissions:
```bash
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 {} \;
```

- 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](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.