Migrating Drupal 8 to Drupal 9

  • will
  • administrator
Submitted by will on Mon, 12/15/2025 - 21:10

Overview
The move to Drupal 9 was a far better experience, although not without bugs. Fortunately some googling and database foo fixed them.

Strategy
There is no migration process for this upgrade. I will clone the environments to a new location and then upgrade that copy.

I will do most of this from the command line. The exception are a few administrative tasks post-install.

Reference:
https://www.drupal.org/docs/upgrading-drupal/drupal-8-and-higher

1. CLONE DATABASE
I've been using the old_user account for a long time. Time to generalize:


CREATE USER new_user WITH PASSWORD 'password';
CREATE DATABASE new_db WITH TEMPLATE old_db OWNER new_user ENCODING UNICODE;

The permissions will be a mess. Let's fix them:

GRANT old_user TO new_user;
REVOKE ALL PRIVILEGES ON DATABASE new_db FROM old_user;
REASSIGN OWNED BY old_user TO new_user;

Check that the move to the new user was successful:

\dt
\ds
\dv

Everything should reference the new user and the old user should not be present.

2. CLONE DRUPAL 8
Put Drupal 8 into maintenance mode.


cd install_dir
mkdir 9
cp -aR 8 9
chown -R www.data-www.data 9
cd install_dir/9/web/sites/default

Update settings.php to reference the new database.

3. CLONE APACHE
Update apache:

cd /etc/apache2/sites-available
cp drupal8.conf drupal9.conf

Update contents of drupal9.conf to reflect the new install_dir.

a2dissite drupal8
a2ensite drupal9
systemctl restart apache2

4. PREP FOR UPGRADE TO DRUPAL 9
Verify Drupal 8 no updates needed at www.teramari.us/update.php.

Upgrade drush to version 10:

cd install_dir/9
composer require 'drush/drush:^10'

Reference:
https://www.drush.org/13.x/install/#drupal-compatibility


chmod 777 web/sites/default
chmod 666 web/sites/default/*settings.php
chmod 666 web/sites/default/*services.yml

5. DRUPAL 9 UPGRADE

cd install_dir/9/
composer require 'drupal/core-recommended:^9' 'drupal/core-composer-scaffold:^9' 'drupal/core-project-message:^9' --update-with-dependencies --no-update
composer require 'drupal/core-dev:^9' --dev --update-with-dependencies --no-update
composer update

Updating the database did run into issues. fortunately this release is so old all the workarounds are on the web:

psql new_db new_user
DROP SEQUENCE "users_uid_seq2"; (may error)
ALTER SEQUENCE "users_uid_seq" RENAME TO "users_uid_seq2";


cd install_dir/9
vendor/bin/drush updatedb


chmod 755 web/sites/default
chmod 644 web/sites/default/*settings.php
chmod 644 web/sites/default/*services.yml

Reference:
https://www.drupal.org/project/drupal/issues/3275916

User accounts and passwords should be unchanged from Drupal 8.

6. DRUPAL 9 POST-INSTALL
Setup upgrade_status module:

composer require drupal/upgrade_status

Setup composer_deploy module:

cd install_dir/9/
composer require 'drupal/composer_deploy:^1.0'

Browse to https://www.teramari.us/admin/reports/upgrade-status

Clear any issues there _if they make sense_ (since we are not actually upgrading to Drupal 10):
1. remove unused deprecated themes
2. remove unused deprecated modules
3. update database
4. enable a PostgreSQL extension on the database:

psql new_db new_user
CREATE EXTENSION pg_trgm;

Browse to www.teramari.us/admin/reports/status and clear the errors (they seem to vary between installs):
Install uploadprogress package:

apt-get install php-uploadprogress

Install PHP ACPU package:

apt-get install php7.4-apcu

Exit maintenance mode.

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

7. TEST
Write up the upgrade notes (this doc) as a blog post. It should post with no errors.

Planning
Upgrades to Drupal 10 and Drupal 11 will come in 2026 along with an upgrade to Debian 12 and Debian 13.

For now I will research improvements to security and performance on Drupal 9.

© 2007-2023 Will DeRousse

No comments available.
Powered by Drupal