So you’re playing with setting up a cool project or web application (like the one I show you how to set up in my new Udemy course), and you want it to be accessible for your friends, your family, and yourself (while traveling away from your home network). How do you set that up?
Buckle up; I’m about to explain all the things.
Disclaimer: this post contains links to third-party hosting companies. Some of these links contain referral codes which give free hosting credit to you (and to me, when you buy through the link). I am not recommending any companies that I don’t actually use in real life.
For many projects, a virtual machine or container running on your laptop, or a Raspberry Pi running on your local area network (LAN) is enough. You can install software, play with services, and host a little website that users connected to your home WiFi network can visit. But when you want to run public servers, reachable from anywhere on the Internet, you’ll need to take a slightly different approach.
There are two schools of thought here:
- (Don’t worry if this is confusing) Use a dynamic DNS service to point traffic to your home network, and then set up port forwarding from your home network router to the machine running the services you’d like to expose on the Internet. This can be complicated and dangerous, and therefore I don’t really recommend it for beginners.
- Rent a server on the Internet. This used to be an expensive decision, but now you can get an amazing amount of processing power and bandwidth for something like $5/month. There are even some ways to get a free year of hosting on platforms like Amazon Web Services, if $5 (USD) is too pricey for your budget.
In this post, I’ll talk about option 2, because for 99% of you, it’s the better option.
First off, just to cut down on confusion: there’s a weird shift happening in IT jargon. You can ignore all the cloud stuff, because it’s just a marketing term for ‘virtual machines on shared hardware in someone else’s datacenter.’ What was once a ‘shell account’ or a ‘Virtual Private Server’ is now called “cloud server,” “droplet,” “cloud instance,” and a bunch of other weird Web 12.0 names. No need to be confused.
How it Works
The way it works is: a company which operates a datacenter (a room filled with servers, usually with at least one connection to the Internet and some form of backup power) wants to make the most money from this investment. They divide their physical hardware up so that each physical server (usually a beast with 10 processors and hundreds of Gigabytes of RAM, or memory) is running tens or hundreds of smaller virtual machines.
Each virtual machine has some chunk of the host machine’s (beast machine) resources. It can use some sliver of CPU time, some chunk of memory, some limited amount of disk operations per second, and a bit of the available bandwidth. There are systems in place to make sure that one virtual machine doesn’t start soaking up all the resources that should be fairly shared with other VMs running on the same host machine.
These virtual machines can usually run whichever operating system you’d like (from Windows to Linux to BSD Unix to more specialized operating systems). This is often called KVM or full virtualization. There are other kinds of virtualization, like containers/LXC, but those aren’t important right now.
Basically, your virtual machine thinks it is an entire server, even though it’s just a tiny logical sliver of a bigger physical machine. You can rent this server for a fraction of what it costs to run the entire host machine (beast machine).
There are some downsides that come with running on a tiny chunk of someone else’s hardware, along with many other virtual machines. Performance can vary greatly, depending on what other Virtual Machines (VMs) on your server are doing. Is there a porn site hosted on a VM next to you? Your available bandwidth might suddenly drop for no obvious reason. Is someone doing a huge amount of database writes on another neighbor-VM? Your disk access latencies might spike, and there’s nothing you can do about it. With some providers, you don’t even have any kind of uptime guarantees for individual VMs.
Keep these things in mind before you run critical infrastructure in ‘the cloud.’
Companies I Use (and recommend)
There are a few companies I’ve used both in my professional life and for hobby projects, and I can heartily recommend them here.
A rapidly-growing newcomer.
Their pricing is good, their wiki is filled with useful tutorials and information, and their hardware is excellent. There’s also a wide variety of supported operating systems, which makes this a great platform to start on. Click here to set up your first VM (using that link gets you $10 in account credit when you sign up and add money to your account; enough to run a VM for two months).
Less hip and cool, but just as excellent as DigitalOcean. Sometimes cheaper.
I’ve been using this company for a while, mostly because they had great support for FreeBSD, which I used heavily for several projects last year. Click here to check them out: they’re a bit cheaper for some things than DigitalOcean, and are excellent in all the same ways.
Sometimes you need a physical machine. Here are a few great providers, which offer excellent prices for when you need more power, dedicated hardware (so you can have some basic performance guarantees), and a bit more ‘enterprise’ capability:
Sometimes you can find crazy-good deals here: physical machines with 4 cores, 16 or 32 Gigabytes of RAM, tons of bandwidth, and 16 ipv4 addresses for incredible prices like $40/month. Definitely worth checking out, and almost as easy to manage as a Virtual Machine at a ‘cloud’ provider.
Great pricing on larger physical servers. For serious projects, I often rent hardware here. 8-core servers with 32 or 64 gigs of RAM often go on sale for $50-60/month. I’ve been really happy with this company, except that they try to sell “DDOS protection” as an add-on service and put Tor relays on a different network.
A really cool little company: they do both virtual and physical servers for excellent prices. They’ve got physical x86 and ARM servers for really cheap (starting at $3/month), and Virtual Private Servers on x86 hardware starting at the same price. Migration between physical and virtual is possible.
Final Thoughts on Physical vs. Cloud
The performance/price ratio of modern physical servers can inspire wonder at why some of these new-age startups spend $30,000/month on a few VMs when they can easily get several times the performance for a tenth of the price running physical machines that have higher reliability, less variance, similar setup time, and wayyy better mean-time-to-failure than best-effort VMs.
However, nothing beats a quick spin-up of a cloud VM to experiment with new services or software. Educate yourself, and use the right tool for the job.