Self-Hosting Appwrite on Azure

Deploy Appwrite on Azure with this step-by-step guide

Self-Hosting Appwrite on Azure

Backend development has held up to its notorious reputation for a while now. If you've groaned about it, you're not alone. But what if I told you there's a way it can be made easier and faster? Ahem, let me introduce you to Appwrite.

Appwrite is an open-source Backend-as-a-service (BaaS) for developing Web, Mobile, and Flutter applications. It provides developers with everything they need to build secure, modern apps fast.

Read this really cool article I found online to know more (I insist👀).

How to use it? Well, there are two primary ways - you can either use the ready-to-go Appwrite Cloud or take a more hands-on approach by self-hosting it. If you're intrigued by the idea of hosting it yourself, I gotcha! In this blog, we will dive into the step-by-step process of deploying Appwrite on Azure.

"But wait, hosting? on a cloud provider? Why go through the hassle?". Well well, let's take a moment to clear things up.

The reason...

Self-hosting often sounds like an extra step, but here are some reasons to go for it👇

  • You are in charge: You have full control over things. You can tweak and customize the backend to perfectly suit our application's needs.

    Let's take a small example: Rate limits and timeout values can be annoying, right? For instance, Appwrite Cloud limits a function's timeout to 15 minutes. But when self-hosting, you can adjust these limits to your preference😉.

  • No Vendor Lock-In & Ultimate Flexibility: What's that? It's when you're so dependent on a specific provider's ecosystem that moving away feels like an impossible task. Whether it's because of specific tools, configurations, or even costs. But guess what? With Appwrite being open-source, this isn't a nightmare you have to live. Unlike many platforms that dictate terms, Appwrite can be hosted anywhere.

Why on a Cloud Provider? While you could technically host Appwrite on a server in your garage(if you're into that, no judgment!), cloud platforms offer more, in terms of robustness, scalability, and security. It's like combining the freedom of self-hosting with the powerhouse capabilities of a leading cloud provider.

"But why specifically Azure?" Great question!

Why Azure?

With Microsoft's legacy, Azure offers infrastructure prowess that’s hard to rival. For scalability, top-notch security, and an array of tools to elevate your backend, Azure is the place to be.

Let's get started!

First, let's understand how things are going to work. So, Appwrite installs as a Docker image(a lightweight, standalone, and executable software package that includes everything needed to run a piece of software). We simply need to deploy this image on Azure. We're going to break the whole process into 5 simple steps👇

Prerequisites: Register for your Azure account from here.

Steps:

  1. Creating an Azure Virtual Machine

  2. Connect to the Virtual machine

  3. Installing Docker & Docker compose

  4. Installing Appwrite

  5. Testing

Time to get our hands dirty!⏱️


Creating an Azure Virtual Machine

A Virtual Machine(VM) is no different than any other physical computer like a laptop, smartphone, or server. We will be using Azure Virtual Machine to deploy our Appwrite instance.

Once signed in, the portal will open and you will be able to see a list of services.

  1. Click on Create a resource.

  2. Click on Create under Virtual Machines.

  3. Fill up the details. Some fields that you need to take care of👇

    • Virtual machine name: I named it appwriteServer

    • Size: I opted for Standard DS1_v2 - 1 vcpu, 3.5 GiB memory

      (Note - The minimum requirements to run Appwrite are as little as 1 CPU core and 2GB of RAM, and an operating system that supports Docker)

    • Authentication type: Make sure its SSH.

    • Select inbound ports: Check http, https and SSH, all three.

  4. Click on Review+Create.

  5. Once the validation test passes, Click Create

  6. You will be prompted to Generate a new key pair. Click on "Download private key and create resource" and save the .pem file in a local directory.

Connect to the Virtual machine

Now it's time to create an SSH connection with our VM. Why do we need to do that? to enable secure remote access.

  1. Once VM is deployed, click "Go to resource".

  2. In the Connect section, go to SSH tab.

  3. Paste your private key file name in the Private key path field.

  4. Open your terminal, navigate to the directory where you saved your private key file, and finally run the command provided to connect to the VM.

    ssh -i APPWRITE_key.pem azureuser@20.2.72.115

Installing Docker & Docker compose

Appwrite requires Docker Compose. Let's install it by running the following commands in our terminal. You can alternatively refer to these Docker docs.

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS

     sudo apt-get update
     sudo apt-get upgrade
     sudo apt-get install ca-certificates curl gnupg
    
  2. Add Docker’s official GPG key

     sudo install -m 0755 -d /etc/apt/keyrings
     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
     sudo chmod a+r /etc/apt/keyrings/docker.gpg
    
  3. Use the following command to set up the repository

     echo \
     "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  4. Update the apt package index

     sudo apt-get update
    
  5. Finally, install Docker using this command. This will install Docker Engine, container, and Docker Compose.

     sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
  6. Once this command is completed run this command to check if Docker is running.

     sudo systemctl status docker
    

Installing Appwrite

All that's left is installing Appwrite, and all it just takes is this single command👇.

docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:1.3.8

Testing

Alright! Everything is set. Let's test it out!

  1. Back in the overview, you will find a Public IP address.

  1. Open it in your browser and voila! There it is, the Appwrite console.


We did it! Hosting Appwrite on Azure is that easy😏.

Now you can go ahead and harness your Appwrite superpowers. Need some help with getting started with Appwrite? Check out these resources👇

🤍Appwrite Docs

💙Appwrite Discord Community

❤️Awesome Projects built with Appwrite