VPS upgrade

Some notes for myself about upgrading/updating/migrating my DigitalOcean VPS to a new OS release.

1. Make sure everything's backed up.

2. Create a new VPS (I'm giving these all the same name, with an incrementing integer appended for each new one) and get its IP address. Create it in the same region as the old one.

3. Log in as root and set a few basic things, and create a new user:

hostnamectl set-hostname bright2.samwilson.id.au
update-alternatives --config editor
adduser sam
usermod -aG sudo sam

Add the user's public key to /home/sam/.ssh/authorized_keys (making sure it and its parent directory are owned by the user), and now you can log in as the new user.

4. Disable root login by editing /etc/ssh/sshd_config and setting these:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

then restarting ssh with sudo service sshd restart

5. Install Apache, MySQL, and PHP:

sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install apache2 letsencrypt python-certbot-apache php7.2 php7.2-mbstring php7.2-xml  mysql-server mysql-client git

6. Turn off Apache on the old server and run one more backup of the databases.

7. Disconnect the storage volume from the old server. DO docs.

sudo umount --verbose /mnt/volume-sfo2-01/

8. Connect the storage volume to the new server.

$ mkdir -p /mnt/data
# Mount your volume at the newly-created mount point:
$ mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_volume-sfo2-01 /mnt/data
# Change fstab so the volume will be mounted after a reboot
$ echo '/dev/disk/by-id/scsi-0DO_Volume_volume-sfo2-01 /mnt/data ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab

9. Restore all databases:

gunzip < alldb.sql.gz | mysql -u [uname] -p[pass] [dbname]

10. Backups.

18 4 * * 3 /mnt/volume-sfo2-01/backups/backup.sh

11. Other stuff.

## MediaWiki jobs.
* * * * * /usr/bin/php /var/www/mediawiki/maintenance/runJobs.php --wiki=wikiname > /dev/null
post_max_size = 200M
upload_max_filesize = 200M
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

MySQL backup user needs: GRANT SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER, LOCK TABLES ON *.* TO 'backup'@'localhost';