Ubuntu 18.04 to 20.04,ghost 5.12 to 5.49,mysql 5 to 8, mega upgrades

Ubuntu 18.04 to 20.04 upgrade

Before doing any updates/upgrades please do backups...

OK, warnings aside lets break s... I mean get things updated

Lets start with an updated... old install

apt update apt upgrade

ymmv, but for many reasons... do-release-upgrade didn't work for me. if it works for you, please do that.

do-release-upgrade

I had lots of issues with packages being held back and didn't want to upgrade. So the next sensible thing (I think) is to just force the upgrade (if you are not comofortable knowing you will have to break broken stuff/this is an important system, be careful before proceeding)

Updated sources.list to point to focal
sed -i.save s/bionic/focal/g /etc/apt/sources.list

ran upate for the repos then an upgrade
apt update; apt upgrade

Then a reboot, now we are on 20.04

once that was done... time to fix lots of broken packages

Ghost updates/fixes

after the 20.04, lots of packages were either with held or broken. Lets fix that
The following were some of the packages i had to manually force install to eventually get upgrade to work without packages being withheld. Ultimately apt did actually resolve all the depedencies, it effectively wanted to make sure I knew what I was doing....

npm install -g npm
npm install -g ghost-cli@latest
npm install -g node-gyp
npm install -g --force node-g
npm install -g @npmcli/fs
apt install gyp
apt install mysql-server
apt install node-server
apt install node-gyp
apt install libgbm1
apt install libgl1-mesa-dri
apt install libpolkit-agent-1-0
apt install libnode-dev
apt install node-npmlog
apt upgrade

From there it's time to install the updated nodejs repo and files. Not its not recommended to run a shell script directly from a site like this. You can donwload the script and manually review it before running it.
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&sudo apt-get install -y nodejs

Now to actually update ghost

assume your ghost user and run updates (not a bad idea to run backups here either)

su -s /bin/bash insertghostuserhere
cd yourghostinstalldir
ghost update

This went mostly fine. The only issue was, afterwards the site didn't actually work anymore

ghost doctor
helped some, by pointing towards a db issue (some here, some there, some everywhere)

I had to open up the ghost config file and edit a couple things.

  • Updated db client to mysql (mine had mysql2 for some reason)
  • updated db host details to be 127.0.0.1 ( previously it was localhost)

shutdown ghost first, then make sure its no longer running

ghost stop
ghost ls
vim config.production.json

after those changes, I thought surely it would work.
I was mistaken
ghost run
revealed more db issues. This time it was related to mysql 5 to mysql 8 schema changes that need to be updated

Mysql 5 to 8 schema fun times

There are a couple ways to handle the upgrade, either directly alerting the tables directly or by dumping the db, updating the dumped db file then loading it back.

I went with just updating the db directly.

There are a couple steps here, first getting the alter table commands, put that into a .sql file. Then you log into the db, temporarily disable foreign key checks, load the alter commands and finally re-enable foreign key checks. Afterwards restart the db

Lets see how that looks in command form

  1. mysql <database> -u <username> -p -B --disable-column-names -h localhost -e 'SELECT CONCAT("ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; ", "ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;") AS alter_sql FROM information_schema.TABLES WHERE TABLE_SCHEMA = database();' > update_schema.sql
  2. mysql <database> -u <username> -p
  3. SET FOREIGN_KEY_CHECKS = 0;
  4. source update_schema.sql
  5. SET FOREIGN_KEY_CHECKS = 1;
  6. quit
  7. service mysql restart

If everything went well, you are now ready to start ghost, and enjoy your updated software
ghost run

...It actually works!


Helpful links
https://github.com/TryGhost/Ghost/issues/16020
https://chronicler.tech/ghost-mysql-upgrade/
https://www.ajfriesen.com/ghost-migration-fails-how-to-migrate-the-default-collation-from-mysql-5-to-mysql-8/
https://ghost.org/docs/faq/supported-databases/#how-to-update-mysql-5-to-mysql-8