Change Moodle domain

Change /var/www/moodle/config.php

$CFG->wwwroot = 'https://mynewdomain.com';

Change URLs in database using moodle cli. Run in /var/www/moodle directory command:

php public/admin/tool/replace/cli/replace.php --search=https://old.com --replace=https://new.com

Purge caches:

php public/admin/classes/form/purge_caches.php

+ DNS
+ certs

If needed – export db from former server:

sudo mariadb-dump -u <db_username> -p --single-transaction --quick <db_name> | gzip > backup.sql.gz

Import to new server:

gunzip -c backup.sql.gz | mariadb -u <db_username> -p <db_name>

If needed to turn off maintenance mode:

php admin/cli/maintenance.php --disable