Oracle offer a limited set of free cloud hosting which is ideal for hosting personal blogs and other websites. The system takes some getting used to, and there are two layers of security systems: the operating system, and the virtual network which the OCI instances connect through. I’ll cover this latter but right now want to document the moving of WordPress.
Backup the Working WordPress Instance
This site lived on a Debian GNU/Linux instance hosted on Linode. After manually upgrading the Debian GNU/Linux release I’ve been having intermittent booting issues making the WordPress host unreliable; this is probably why Linode does not recommend doing release upgrades and suggests moving data to a new instance instead. I have chosen to save some dollars and the accompanying foreign currency conversion fees by moving to OCI.
- Connect with SSH to the current virtual machine
- Become the root user if you are not already:
- Stop the web service to ensure a clean site backup, making sure that there are no users working with WordPress:
service apache2 stop
- Backup the WordPress files which are likely located in
/var/www, in this example the command is:
- cd /var/www
- Stop the database server:
service mariadb stop
tar -cvzf macintosh-rescue.net.tar.gz macintosh-rescue.net
mv macintosh-rescue.net.tar.gz /home/andrewread/
cp /etc/apache2/sites-available/macintosh-rescue.net.conf /home/andrewread/
- Remove three lines from the .conf file which begin: “Rewrite”, since they are all related to certbot and will need to be regenerated later.
- The database server must be started before the WordPress database can be “dumped”:
service mariadb start
- Now we need to backup the WordPress database and that can be done on a Debian GNU/Linux system like:
mysqldump --add-drop-table -h localhost wordpress > database.bak
chown andrewread macintosh-rescue.net.tar.gz macintosh-rescue.net.conf database.bak
Setting up the New Host System
It’s now time to create a new web host instance on the desired cloud provider, or maybe even your very own server. I’ve chosen Oracle Cloud Infrastructure purely based on the cost: free! If this wasn’t the case I’d host from my own server behind my broadband connection which would easily cope with the traffic that this little site gets.
I have setup an Ubuntu 20.04 (LTS) instance which is one of the platform provided images from Oracle. I recommend Debian GNU/Linux, Ubuntu or similarly available systems for web hosting; they are just so much easier to manage than the likes of Oracle, CentOS, or other Red Hat Enterprise Linux derivatives.
To get this server going I needed to do the following:
- Connect to the system with the SSH Key that OCI generated for me; there is no user account password! On my Mac I open the connection with:
ssh -i keyfilename.key ubuntu@thepublicipofyourinstance
- Update the system:
sudo apt update
sudo apt dist-upgrade
- Install mariadb:
sudo apt install mariadb-server
- Secure the mariadb installation with:
sudo mysql_secure_installation #entering a root password then selecting all defaults
- Install apache2 and WordPress dependencies with:
apt install wordpress curl apache2#although we are not using the packaged WordPress installing it conveniently allows apt to calculate dependencies that are needed for WordPress to work
- Install Certbot for free SSL certificate generation:
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
- In OCI the Ubuntu 20.04 image has iptables firewall running so we need to enable traffic to reach the hosted sites with:
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save
Instating Site and Database
Now we copy the backup data from the old host which should still be running, then enable it all.
- From the new host use scp to copy the three backup files for example:
scp email@example.com:/home/andrewread/database.bak#then for the tar archive and the conf file
sudo mv macintosh-rescue.net.conf /etc/apache2/sites-available/
sudo mv macintosh-rescue.net.tar.gz /var/www/
- Recreate the database with the same username and password as on the previous host system:
mysql -u adminusername -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5340 to server version: 3.23.54 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> CREATE DATABASE wordpress; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpress"@"localhost" -> IDENTIFIED BY "wordpressdbpassword"; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> EXIT Bye
- The new database can now be populated with your WordPress sites data from the backup file with:
mysql -u wordpress -p wordpress < database.bak#enter the wordpress database password when prompted
- Now we need to unpack the WordPress files into the location they are to be served from which must be the same as on the previous host. I did the following:
sudo tar -xvzf macintosh-rescue.net.tar.gz
- To enable the WordPress site we need to enable it from the .conf file stored in /etc/apache2/sites-available by:
sudo a2ensite macintosh-rescue.net
- Reload the web server with:
sudo service apache2 reload
- Now is the time to change your DNS records on the internet to point to the new web host, and verify that the new address is resolved.
- I was unable to test the non SSL secured site because the version of Safari I browse with defaults to https, so now it’s time to get that working:
sudo certbot#follow the prompts and make the site SSL
- Try accessing your WordPress site over the internet, make sure that images load, and that you ca save edits
If that’s all working you can get rid of your previous host, and possibly start saving money! I recommend that you regularly backup your WordPress site in a similar fashion to the first stage of this tutorial. You could even automate periodic backups with a scripted cron job.
Happy WordPress Hosting!