Getting a Website Online (cheaply)
You followed a tutorial, or maybe used an AI. However you did it, you now have a website you want to put online. It runs great on your local machine, but now you don't know what to do so other people can see it. The AI is only able to get you so far before it gets tangled up in DNS records and TLS ACME challenges and a bunch of other weird acronyms. A Google search didn't help either. Why is all this stuff so expensive?
The cheapest way you can get online? Host on Github Pages, Sourcehut Pages, or similar and use the domain name they give you. There's a lot of limitations, like it has to be a static site, but that might be what you built. And it's free.
Do you want your own domain name? Easy, start by buying it from a registrar. You can find lots of recommendations online, I like Porkbun. Don't get too attached to a name before you know it's available and the cost. Follow the instructions for the place you're providing. Github's instructions aren't very hard to follow, even if it includes weird files named CNAME and adding "A" records.
Is your website more complicated than static files? Well, now you've probably found something like Fly.io or Railway that promises to run a container for you. Or Vercel that will "magically" run your project if you only use their technology and don't ask too many questions.
But you want it built it the way you have it. You don't want to rebuild it. And you don't want to be locked into a vendor that won't help you. These guys get expensive pretty fast once you get off their freeish-happy-path tier of usage. There's a different way. So tried and true that once you have it setup, it'll probably never need to change. You don't find many tutorials about it cause no one is selling this stuff. It just works, people just use it. It underpins all of these other companies. At least, I haven't found many tutorials.
Run a VM.
A Virtual Machine (VM) is a full computer somewhere in some cloud. For this tutorial, you'll want a Debian or Ubuntu operating system on it. Because the OS is what we're after, you can use any vendor that offers a good price. DigitalOcean, Hetzner, and Linode are some good options. These are usually a flat monthly rate instead of usage rates like some of the other deployment options. I guess technically they're usage rates, but it's just time the VM is on.
Then we run software on the VM to get online. It sounds intimidating, but this article is a crash course. It's meant to provide some guide posts, even if it doesn't give you every line of code. I want you deploying your site, that's different than my site. But I believe this system is so flexible that it will work for you. And I believe you'll be able to pull it off.
We'll talk about two significant pieces of software, and one that might be important for you. systemd, caddy and podman. This trifecta will let you easily run your website on a VM.
So start with a VM. Make sure it has Debian or Ubuntu on it, that ensures we already have systemd on it for us. systemd is what starts the computer; it's a process monitor. Your website might need a process and systemd is good at making sure that process stays running. Caddy is a process, so we'll need systemd to watch it at the very least.
Let's get your website on the computer.
If the site is static, you can just upload those files and go on to telling Caddy where they are. rsync is a great option to upload them, so is Cyberduck. Your VM provider should be able to direct you to getting SSH access to your VM to upload these files, it's the primary way you'll interact with the VM while setting it up. (If you need to set up SSH keys for access, I'm sorry that's out of scope for this post. Just know that if a password won't work, you might need an SSH Key.)
If the site isn't static, I suggest you build a container for it. You can upload it to a public registry if you want. That's beyond the scope of this tutorial too, but however you built your website there's probably a template for you out there. You can mess with uploading the image to a registry, but I don't. I save the image on my machine, then upload the image over sftp like the static site version. Load the image on the other side and you're good to tell systemd what process to monitor.
What process do you tell systemd to monitor? If it's not a container (just a binary you run), you can write a unit file directly. If it is a container, you'll want to install podman and write a quadlet unit file. It has to be podman, docker or other runtimes don't have support for quadlets. Quadlets let us run containers under systemd process supervision as if they were normal processes. The unit file you write is very reflective of a Docker Compose or a Kubernetes config (or the command line container arguments), but is a simpler format than YAML. I like to link these to the proper place using ln -s, but you can also copy them directly with cp. Don't forget to reload your daemon! systemctl daemon-reload
Now we're ready to install caddy. This is our gatekeeper, making sure only the internet traffic we want enters into our website. Caddy runs as a process monitored by systemd, installing from the debian repo installs the unit file for us too. See it running with systemctl status caddy. Now we can set up both sides of our gate.
Tell Caddy where your site is.
If it's static, you can use the file_server directive. If it's a different process, you can use the reverse_proxy directive. You'll need to edit the Caddyfile located at /etc/caddy/Caddyfile, which you may need sudo to edit. In most VMs, you're already root and don't need to worry about it. nano and vi are two editors your VM should have. <ESC>:wq to quit vi, if you decide to try it.
You need to pick a domain name when you edit the Caddyfile. You can use the "apex domain", yourdomain.com, or a subdomain like blog.yourdomain.com. Now that you own a domain name, you can name and host almost infinite websites at subdomains. Whatever you choose, remember it for this last part.
Last, tell the internet about your VM.
Point a DNS "A" record to the public IP address of your VM. This means you'll get to login to your VM provider and your registrar and copy some numbers over. This is also where need to remember what you told caddy your website would be named (yourdomain.com? blog.yourdomain.com? Something else?). Once you've saved this record, you should be able to navigate to it in your web browser. Sometimes DNS takes a few minutes to propogate.
Congratulations, you're online!
There are a few moving parts here. I didn't say this was the easiest way to get online; I think the flexibility and scalability outweighs all that over time. You can learn these pieces of software once and deploy anything, anywhere, anytime. It might cost you $6/mo, including for your domain. You might be able to host multi websites for that same $6, so the money doesn't have to hold you back from exploring this great world of computing and being online.
I hope you enjoy your site and being able to share it! Helping more people get online brings me great joy, I hope you're able to learn from some of my experience.