My Experience with a Drupal 8/9 Update Part 1: The Local Environment
Tags: webdev, php, programming
Published: 2021-08-03 17:51:25

Part 1 | <a href="https://dev.to/nevkatz/my-experience-with-a-drupal-8-9-update-part-2-the-remote-site-12c7">Part 2</a> |  <a href="https://dev.to/nevkatz/my-experience-with-a-drupal-8-9-update-part-3-database-updates-30na">Part 3</a>

Monday night was one of those nights that I couldn't look away. I kept trying to upgrade my Drupal 8 site using a number of strategies, all to no avail. By the end of a long night I was soundly defeated by Drupal and its nefarious sidekick, Composer. 

At least they seem adversaries in those moments. In the best of times, they are great allies that just get a little cantankerous sometimes.

One day later and I am back at it again - working on upgrading a multiple-website system from Drupal 8 to Drupal 9. 

In this article I am listing out the Drupal migration tips and tricks that I wish I had known at the outset of this journey.

While this will not entail a complete rebuild along the lines of Drupal 7 to Drupal 9,, one challenge is that this is a Drupal multisite system where 20+ sites have to be upgraded.

## Jargon
For those of you new to the jargon, Drupal is a content management system with endless possibilities but also endless headaches at times. Composer is a dependency manager that helps to keep Drupal's various dependencies all straightened out.  

Symfony is a popular PHP framework that you're not supposed to have to adjust - it's like node_modules in that regard. It was throwing errors during the direct upgrade and the core reason I am changing my approach from a direct migration to a ground-up build.

## Approach
My strategies: 
* Starting at Drupal 9.0.1 since it is closest to Drupal 8.9.17.

* Using Lando for my local setup.

* Starting with a Vanilla Site, then will make a backup.

* settings.php file and directory structure is modeled after our current site, which resides on Acquia Cloud.

* git repo comes from our current site; I swapped in new vendor, the web directory, and other key directories that are all 9.0.1.

## Starting with a Drupal 9 instance


At first, I was trying a direct upgrade from Drupal 8 to Drupal 9. Because this introduced too many complications, I have switched to building a 9.0.1 site from the ground up. 

Once I'm ready I plan to add the contrib modules and import my database.

My approach of building the D9 site from the ground up and then adding in assets is for several reasons: 
* We want to switch our local systems from Acquia Dev Desktop to Lando, and this is a good opportunity.
* Upgrading a D8 install directly to D9 introduces issues with symfony dependencies that are hard to parse out. 
* lightning modules upgrades got especially tough, so starting with D9 allows me to  reinstall the correct versions more easily.


## Key Takeaways Thus Far
A few things I have learned: 

If your webroot is not toplevel you have to update it in multiple places in composer.json.

You get into a chicken-and-egg situation with composer you can update all at once with <code>composer require resource1:x.x.x resource:y.y.y --with-all-dependencies</code>

Sometimes obliterating composer.lock and vendor directories are a great way to go.

I'll probably update this post as I find out more. Hope this helps other Drupallers out there.

## General Updates

Below are some updates I posted throughout the day (8/3/21).

* My local blank hub site is working. Yay!

* I am now gradually adding modules with Composer and listing out the ones that do not install. For those, we will see if we can turn them off on our 20+ live sites before the code upgrade.

* Overall my trust in Composer is returning after the debacle yesterday.

* After installing the required modules, I then installed the theme. This requires changing some compatibility in their .yml files. Backing up the site while the base theme is installed has been critical. Replacing <code>core:'8.x'</code> with <code>core_version_requirement: ^8 || ^9</code> in the <code>theme.info.yml</code> files seems necessary but not sufficient.

* I just installed the Upgrade Status module, which tells me that none of my modules are ready for Drupal 10. Who cares about 10? I'm still trying to get to 9! It also may help me to figure out why my themes are incompatible. This way I can learn about why they don't work without enabling them.

* Well, well, well. Even though the themes are in the green now, I am back to getting a symfony error related to a dependency injection.  This is what drove me to switch strategies, but now I have a better idea of what triggers it. It seems to be a theme issue.


The error from admin/reports/dblog is below.

<pre>
<code>
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "path.alias_manager". Did you mean this: "path_alias.manager"? in Drupal\Component\DependencyInjection\Container->get() (line 151 of /app/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php).
</code>
</pre>
* After a bit of searching I ran across <a href="https://www.drupal.org/project/rules/issues/3101026">this resource</a>, which was the key. I had to change <code>path.alias_manager</code> to <code>path_alias.manager</code> in three places.
* It worked! The Porto theme now shows up. 
* Importing the database from our hub site still causes errors.
* It is amazing what I am learning by re-adding all the site assets. I now see that I have needed some profiles in our  <code>profiles</code> directory. On the <code>update.php</code> page Now I see a bunch more missing modules that I thought were optional.
* All modules are added. The lightning media and entity_embed_link module had to be added manually to get to the update screen.
* I am now going through 112 database updates.
* Getting a white screen, but running <code>lando logs</code> indicated it was due to one line of deprecated code in the theme. I am changing <code>entity_load_multiple_by_properties</code> to <code>loadByProperties</code> in my <code>porto.theme</code> file. 
* The first site works!
* Just tested on the remote site is still a work in progress. I will need make some changes to settings.php but we are moving along. That's all for now!

### Elsewhere

<a href="https://dev.to/nevkatz/my-experience-with-a-drupal-8-9-update-part-2-the-remote-site-12c7">Part 2</a> |  <a href="https://dev.to/nevkatz/my-experience-with-a-drupal-8-9-update-part-3-database-updates-30na">Part 3</a>

<a href="https://nevkatz.medium.com/7-tips-on-upgrading-from-drupal-8-to-drupal-9-648f519d6e7e?sk=fe2d0816cb852a7b5ca3dfaf0b6fa131">7 Tips on Upgrading from Drupal 8 to Drupal 9</a>