Backing up Database for WordPress

To migrate your WordPress site to your own host on Cloud, you have to backup your database. Backing up database is a very simple process as long as your host has phpMyAdmin to manage your database.

  • Login to your phpMyAdmin.
  • Select the database for your WordPress blog.
  • Click Export and then simply click Go.
  • After a while, you get the entire database as a SQL file. That’s it for backing the data up!

Configuring Ubuntu for Containerized Blog Engine

There are some prerequisites on the OS to support Dockerized WordPress.

  • Update OS (packges) with sudo apt-get update && sudo apt-get upgrade
  • Install Docker Engine by executing the following commands.
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
  • Install docker-compose by executing the following commands.
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
  • Install VIM by executing sudo apt-get install vim (This is necessary to edit config files while working on configurations.
  • Install net-tools by executing sudo apt-get install net-tools. This is not a must but it helps to check if your host is listening to the expected ports. sudo netstat -tulp is useful to check the listening ports.
  • Install ufw to manage firewall on Ubuntu. sudo apt-get install ufw
  • Open ports 80, 443 and 8080 by executing the following command. Adding 22 for ssh access.
    sudo ufw allow 80 && sudo ufw allow 443 && sudo ufw allow 8080 && sudo ufw allow 22 && sudo ufw enable

That’s pretty much what you need to get ready your own Dockerized self hosted WordPress on your own Cloud.


Deploying an Ubuntu VM on OCI

Thought you could provision VMs manually using the OCI’s UI, I prefer using Terraform to manage it because you can manage infrastructure as code and provisioning and destroying are easily repeatable.

Here is Terraform code I used to provision my Ubuntu VM.

resource oci_core_instance ashburn-blog {
    compartment_id      = var.tenancy_ocid
    display_name        = "blog-host"
    availability_domain = "Gumm:US-ASHBURN-AD-1"
    shape               = "VM.Standard.E3.Flex"

    shape_config {
        memory_in_gbs = 2
        ocpus = 2
    }
    
    source_details {
        source_type = "image"
        source_id   = var.config["image_ocid"]
        boot_volume_size_in_gbs = 80
    }
    create_vnic_details {
        assign_public_ip = "true"
        hostname_label   = "blog-host"
        subnet_id        = var.config["public_subnet_ocid"]
    }
    metadata = {
        ssh_authorized_keys = file(var.public_ssh_key)
    }
}

Some values are defined in variables.tf file as variables as you can imagine. You may have to get the correct OCID for var.config[‘image_ocid’] by executing OCI CLI command. I have blogged how to list available images before, please refer to this blog post to list images and their OCID.

Once that’s ready, all you have to do is to run terraform apply to provision the VM as the way you want. (I didn’t realize I had 2 CPUs in the VM though I said I had 1 CPU for this blog. htop shows I have 2 CPUs.)