Updating with Composer and Drush is Magical

My Drupal update process used to involve downloading the core update as a zip, unpacking it, deleting from the host, and FTP uploading everything back up again. When I started working on Drupal 8 sites the crazy number of Symfony files and everything made the process take close to an hour. I was able to get that down to about 15 minutes if I had shell access. A decent cpanel that had a file manager with extract operations was about as quick too. Once the vendor and core folders are zipped up I can upload them, delete the old directory and extract the new.

For this site I have a process where I use composer and github to do all of my module and core updates. I'm using 2 environments, one on  my local pc and the remote server. I push everything to github then pull it down to remote.

I usually know already if an update is available but if I want to know what's due I can check from the command line in my site root:

$ composer outdated "drupal/*"

That will list any modules and if the core is needing to be updated.

To update core:

$ composer update drupal/core --with-dependencies
$ drush updb
$ drush cr 

To update a module:

$ composer update drupal/<modulename> --with-dependencies
$ drush updb
$ drush cr

Test everything locally then push it up into git.

$ git add .
$ git commit -m "updates <modulename> to version .xyz etc."
$ git push origin <branch>

Make an ssh connection to the host then do a git pull on the development branch. If I need to run a database update do that then rebuild the drupal cache.

Reverting to a previous module can get sketchy. Not a module but the bootstrap4 theme I just updated did something funky to my subtheme so I looked into rolling that back and it wasn't very clear how to do that in composer. Something about running composer install and the version number but since it's a beta# version it didn't look like that would work. I ended up just downloading the zip and manually updating the files.

Another crazy thing that kept happening is when I would run composer update it would tell me nothing needed to be updated. That was pretty frustrating because the core was definitely out of date. My host runs a security scan to check for outdated software or vulnerabilities (hi A2 hosting!) and lets me know right away if something needs updating. I had to modify some things in the composer.json file and in one instance updating composer got it working again.

This post was very helpful: https://www.jeffgeerling.com/blog/2018/updating-drupalcore-composer-drupal-core-doesnt-update

Drupal documentation: https://www.drupal.org/docs/user_guide/en/install-composer.html

As a consequence it's a much smoother process. I haven't checked or anything yet but I'm thinking it doesn't crash my site when updating like it used to do when I'd delete everything and ftp it all back up again. That always felt kind of awkward to me. Develop in test, but then crash production while it waits for FTP to catch up. Of course there's "maintenance mode" but what good is that when you have deleted everything except your site directory.