Installation or Server Provisioning
Tools for Deployment on VPS
Before we start installing the tools required to deploy projects on a VPS, for the simplest deployments, you need just two tools: a proxy server to forward requests between different services on your server, and a tool (Docker or systemd) to automatically start your app/service in case the server is rebooted or the service crashes. Let’s check what tools we need.
Caddy Server
When you want to open a website in a browser (for example, turbocloud.dev), the browser sends a request to special services (DNS servers; there are many DNS servers, and your browser knows their addresses) to get the IP address of the server hosting the website. After the browser gets the IP address of the server, it sends a request to that server and “attaches” the domain name to the request (in the request headers).
When your server receives a request from the browser, something on your server needs to know that a request with the domain turbocloud.dev should be handled by project A, and a request with turbocloud.dev/book should be handled by project B. The tool that forwards requests to different services within your server is called a proxy server. We will use Caddy as a proxy server because:
- It handles HTTPS and WSS automatically, so you don’t need to do anything to enable HTTPS and WSS with your domains.
- It’s fast.
- It has a modern community.
- It’s easy to use.
- It has a rate limiter (we will check how it works in the chapter “Security”).
- It has a Web Application Framework with a set of predefined rules (we will check how it works in the chapter “Security”).
- It has a built-in load balancer to distribute requests across multiple instances of the same service, which is especially helpful when one instance of a service cannot handle all user requests.
Docker
Docker is a tool that manages containers. For example, if a server is rebooted or your service crashes, Docker can restart the service. If you haven’t worked with containers or Docker before, don’t worry—you don’t need any experience with Docker yet. In the chapter “Deployment from a Local Machine,” we will discuss how it works in detail, but for now, you should just know that we will use containers for most deployments because it’s the best practice for most projects. However, you can deploy without Docker as well—see the next tool.
systemd (if you don’t want to use containers)
Great news! You don't need to install anything on your server if you plan to use systemd to manage your apps and services instead of Docker, as it comes pre-installed with all Linux systems.
This is the minimum set of tools required to deploy an app. It sounds simple, right? However, if you don’t use containers, some additional tools may be required. For example, if you want to deploy a Node.js project without Docker, you should install Node and NPM on your server, just like you do on your development machine. That’s why using a machine with the same operating system (we use Ubuntu 22.04 on our laptops, for example) on both your server and your development machine can reduce the number of possible errors during deployment.
Server Provisioning
Time to provision (or install the required tools on) your server. At the end of this chapter, you’ll find a full provisioning script that you can use to provision a new server with one command from your development machine. However, it’s better to understand how it works, so let’s provision the server step by step. Run these commands step by step in the Terminal on your development machine. You should use a server with Ubuntu 22.04 and a public IP address to avoid errors during installation.
- SSH into your server (as we created in the chapter “Getting a Cloud Server”):
ssh root@ip_address_of_server
- Install Caddy Server:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
- Install Docker and Nixpacks (skip this step if you want to use systemd and don’t want to use Docker or containers):
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") 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 docker-buildx-plugin docker-compose-plugin
curl -sSL https://nixpacks.com/install.sh | bash
Great! You’ve just provisioned your server and are ready for the next step - "Project Preparing".