A Beginner's Guide to Self-Hosting
The world of self-hosting invites creativity, encourages innovation, and most importantly is cool. There are loads of cool services you can setup such as Ghost for blogging, Immich for photo sharing, and even a Minecraft server! Before we get into the how, let's dig into the why.
Why Self-Host?
Imagine you've created the world's coolest pizza website that predicts what kind of pizza a person would enjoy with up to 99.99% accuracy. Being the generous individual you are, you want to share this product with the world via the internet and you scramble to your favorite cloud provider only to find that you've maximized the free trial and need to pay money to host the project. Since you're a cheap college kid, you don't pay for the trial and the project never sees the light of day.
The above example, may be a bit contrived. However, cloud provider costs are typically a large reason that people switch to self-hosting. Furthermore, it only costs about $100 for a mini pc or a Raspberry Pi to start self-hosting. You also lose the cost of cloud providers and can save money in the long run.
What do I need?
The scale of your servers largely dictate your hardware. I have 3 Raspberry Pi 5s on deguzman.cloud, but 1 decently powered machine such as a Raspberry Pi 5 can sufficiently handle several applications with a small number of users.
You'll need a storage device to flash an OS (operating system) to the servers –assuming an OS is not pre-installed or you'd like to change it. If you buy a Raspberry Pi, you can flash it with an SD card. Otherwise, you can flash the servers with USB flash drives (at least 8gb to ensure it can fit general purpose server OS's such as Ubuntu Server).
Since we want our servers to be accessed via the internet, a router is necessary. We will setup port forwarding to send and receive traffic from the router to our servers.
If you'd like to use ethernet for more reliable and quicker speeds, use ethernet cord to connect your servers to the router. Note that most residential routers support gigabit speeds so a cat5e cable is likely what you'll need. If you don't use ethernet, you can use wifi which is slower but I find it to be sufficient.
Lastly, you'll need a domain name. Unless you want people to visit your website via an IP address, you should buy a domain name (they are relatively cheap unless you want a trendy TLD such as .ai or .io). Cloudflare and Namecheap are great DNS providers to shop at.
Putting everything in a list, we have:
- At least 1 computer
- Router
- Flash drive/SD card (depending on your computer and at least 8 gb)
- Ethernet cord (optional)
- Domain name
I have the hardware, now what?
Great! Now that you've gotten all of the hardware assembled, we can start installing the necessary software.
Operating System
The operating system is the first thing you'll need to install (good luck trying to use the computer without it). If you have a Raspberry Pi, you can use their official imager which will flash an OS optimized for the Raspberry Pi to your external storage device (an SD card is highly recommended for Raspberry Pi's). Otherwise, you can use etcher to flash the OS to the storage device and follow the instructions of the operating system you are installing (Ubuntu Server is a popular choice).
Whatever OS you use is up to you. I use Ubuntu Server 24.01 LTS because it is lightweight and plenty of resources online, but you can use any other Linux distribution or OS.
SSH
Once the OS is installed, be sure to enable SSH on the server and ensure it is connected to your desired wifi network (these are typically configured on setup or installation of the OS). SSH is important because it allows us to remotely connect to the servers – this is particularly important if your computer doesn't have a monitor and keyboard connected such as a Raspberry Pi.
If you haven't setup your servers to be accessed via the internet (we'll get to that in a bit) then you can only SSH into the servers via the same network. To SSH into the server, you'll need it's name or local IP address which you can find with utilities such as nmap
or arp-scan
.
If you've given the server a unique name on your network (typically configured when installing the OS), you may be able to ssh into the server with ssh <server_name>.local
replacing <server_name>
with the actual name.
Otherwise, you can use listed utilities to scan your local network for all IP addresses connected to it. You can do a scan before and after setting up the servers and SSH into any new addresses added. If you forget to scan beforehand, you may have to attempt to SSH into all of them.
A big security recommendation is to disable password login and enable key authentication. Password logins are generally weaker and can be brute forced while SSH keys are much longer, complex, and less susceptible to vulnerabilities.
Orchestration Software
Another big decision is to decide what, if any, orchestration software to use for managing the programs running on your servers. This topic can be it's own discussion entirely, so I will keep it brief.
The simplest decision is to not use any software and directly run your projects on the operating system; however, this may pose a security risk and is unscalable.
Typically, applications are run on containers or virtual machines (VMs). Popular container management systems are Docker, Kubernetes, Nomad with Nomad also managing VMs.
Exploring Kubernetes, you may find a large number of distro's such as k3s, k0s, MicroK8s, and Minikube just to name a few. Docker is a popular container management system and is often familiar and simple to many, so I recommend starting there. Both Kubernetes and Docker use containers, but the main differences between them are that Kubernetes handles scaling better and evenly orchestrates containers across servers.
Nomad provides VM and container support out of the box, while Kubernetes and Docker typically only support containers (it is possible to run VM's on Kubernetes with Kubevirt). VM's can provide more base security as opposed to containers since they run via a hypervisor instead of on the host's kernel. If you want VM support, ensure your CPU and OS support virtualization.
I use Kubernetes via k3s for deguzman.cloud because I already knew Docker and wanted to learn Kubernetes. K3s is also a lightweight Kubernetes popular for running on Raspberry Pi's.
Port Forwarding
Now that you've got your servers setup, it's time to connect them to the internet! We do this via port forwarding, which connects your servers to the internet over a specified port(s). For SSH, that port is 22 (you can change it if desired) and HTTP is served over port 80 or 443 for HTTPS.
The steps vary based on your ISP (internet service provider), so it's best to look up instructions on how to do so or call their support line for assistance.
DNS Setup
Your servers are now exposed to the internet, congrats! However, we can't access it via that super cool domain name we bought earlier. You'll need the external IP address of your router which you can find with websites like whatismyip (ensure you're connected to the same network as your router). You'll likely see two results: IPv4 and IPv6. We're only interested in IPv4.
Then, on your DNS provider setup an A
record that points the domain to the IPv4 address. Once setup, it can take up to a day for the address to propagate across the DNS servers.
Conclusion
In this article, we discussed why we'd want to self-host and walked through the general steps of getting servers to setting up the necessary tools. I found all of these things out myself when setting up deguzman.cloud and am now hosting a good deal of projects on my servers. This should be enough to get you up and running, but there is still much you can do!
For example, looking into Nginx and LetsEncrypt are recommended for setting up basic load balancing (distributing traffic from the internet to the correct applications) and SSL certificates (necessary if you don't want to get security warnings when visiting websites).
It may be daunting, but is a great and rewarding project that teaches you about networking and prepares you for industry with tools such as Docker and Kubernetes which are often used in big tech at companies like Microsoft, Amazon, and Datadog.