Today I find myself having to change the domain name of my server. Here are the steps, though the order can be shuffled.
File names on the server
In case I ever need to do it again, I am changing the directory name on the server which files are served from. Instead of
/var/www/myjetsonnano.olddomainname.com
files will now be located in
/var/www/myjetsonnano
Apache2 Sites-Available
Go into the directory and the edit file
/etc/apache2/sites-available/
site.newdomainname.com.conf
replacing all references to the old domain name with the new domain name. The new file can be created by copying the old one, or renaming it if you feel confident.
Enable the site and get an SSL certificate
a2ensite site.newdomain.com
systemctl reload apache2
certbot --apache -d site.newdomain.com
Temporary domain name override in WordPress
To get wordpress back up running, it needs to know the domain name, which is normally stored in its database, but which can be overridden by a couple of lines in the file
wp-config.php
by adding lines like
define('WP_HOME','https://site.newdomain.com');
define('WP_SITEURL','https://site.newdomain.com');
Cleaning up wordpress
When wordpress is working, any old links can be tidied up using this tool.
