Quick & Dirty: Migrate To Composer Drupal 8.8.0

Submitted by Xilodyne on Sun, 07/26/2020 - 17:34

Migrating non-Composer Drupal 8.7.8 to Composer Drupal 8.8.0

Starting with Drupal 8.8.0 the only way to update Drupal is via Composer.  As a Drupal and Composer n00b I failed to have a successful migration to Drupal 8.8.0 following the recommended steps. 

My Drupal environment is plain vanilla without any modules and only one theme and runs on Ubuntu 18.04 LTS.  There are no database updates between 8.7.8 and 8.8.0 and there doesn't appear to be any significant features changes between the versions so the upgrade hack appears to work as expected.

Note:  The steps below are NOT recommended by the official Drupal documentation on how to migrate your environment.

Steps Overview:

  • Update your environment to Drupal 8.7.8
  • Allocate 2GB RAM for your Drupal environment
  • Backup your Drupal environment (files and database)
  • Update to PHP 7.3 and change Apache configuration
  • Install Composer
  • Create a new Drupal 8.8.0 with Composer
  • Copy your Drupal 8.7.8 directories to Drupal 8.8.0
  • Update to 8.9.2 using Composer

Update Drupal to 8.7.8

Follow your normal process updating Drupal manually. 

Increase RAM to 2GB

My Drupal ran fine at 512KB but Composer will have failures if there isn't enough RAM.

Backup up your environment

I also back up my virtual environment (just in case I completely ruin everything).

  • Backup the database
  • Backup current Drupal files

cp -r myblog ./myblog.orig

  • Create a working copy of the old Drupal files, separate from the backup

mv myblog myblog.blog

Upgrade to PHP 7.3

https://www.rosehosting.com/blog/how-to-install-php-7-3-on-ubuntu-16-04/

sudo apt update
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/apache2

sudo apt install php7.3 php7.3-cli php7.3-common
sudo apt install php7.3-xml
sudo apt install php7.3-gd
sudo apt install php7.3-mbstring
sudo apt install php7.3-mysql

  • Configure Apache to use PHP 7.3

cd <apache_install>/conf/mods-enabled
ls -l | grep php

-rw-r--r-- 1 www-data www-data  867 Oct 24  2019 php7.2.conf
-rw-r--r-- 1 www-data www-data   79 Oct 24  2019 php7.2.load

sudo rm php7.2*
sudo cp ../mods-available/php7.3* ./
ls -l | grep php

-rw-r--r-- 1 root     root      855 Jun 20 08:38 php7.3.conf
-rw-r--r-- 1 root     root      102 Jun 20 08:38 php7.3.load

sudo chown www-data:www-data php7*
ls -l | grep php

-rw-r--r-- 1 www-data www-data  855 Jun 20 08:38 php7.3.conf
-rw-r--r-- 1 www-data www-data  102 Jun 20 08:38 php7.3.load

sudo /etc/init.d/apache2 restart

[ ok ] Restarting apache2 (via systemctl): apache2.service.
  • Verify Drupal is running by viewing your website

Install Composer

https://getcomposer.org/

sudo mkdir composer
sudo chown -R drupal_user:drupal_user composer/
cd composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79 ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php
php -r "unlink('composer-setup.php');"

I gave up trying to run Composer as www-data (even though I had changed all file permissions to www-data owner and writable). 

  • Create composer and mysudo aliases in the .bashrc

alias composer='php /opt/composer/composer.phar'
alias mysudo='sudo ' 

  • Source .bashrc to get aliases

. /home/drupal_user/.bashrc

Create a new Drupal 8.8.0 with Composer

Make sure the earlier backup steps were completed.

https://www.drupal.org/docs/8/update/update-drupal-core-via-composer

  • Stop apache2
  • Use composer to create a new Drupal 8.8.0 website

cd /var/www
mysudo composer show drupal/core-recommended
mysudo composer outdated "drupal/*"
mysudo composer create-project drupal/recommended-project:8.8.0 myblog

Copy your Drupal 8.7.8 directories to Drupal 8.8.0

sudo cd myblog
sudo mv web web.orig
sudo mv ../myblog.hold ./
sudo mv myblog.hold web
cd web
sudo rm * 
(delete top files)
sudo rm -r core
sudo p -r ../web.orig/core ./
sudo cp ../web.orig/* ./

  • Change apache2 to see new web directory
  • Start apache2
  • Run the Drupal update website:8080/update.php
  • Verify update worked in website:8080/admin/reports/updates

Update to 8.9.2 using Composer

  • Backup Drupal files

cd /var/www
sudo cp -r ./myblog ./myblog.880

  • Update to Drupal 8.9.2

cd myblog
mysudo composer show drupal/core-recommended
mysudo composer outdated "drupal/*"
mysudo composer require drupal/core-recommended:8.9.2 --update-with-dependencies

  • In the /var/www directory, set owner:

sudo chown -R www-data:www-data *

  • Start apache
  • Run Drupal update website:8080/update.php
  • Verify update worked in website:8080/admin/reports/updates