Self-hosting websites
Published: 2022-10-25A website on the internet is an extremely effective way to spread information. It is so important that most busnesses, professors, and even book authors have a website. If you have your own domain (like this site has selfhoster.dev) then it's also very difficult for other people to take over your domain or take your website down. Unlike social media websites or Medium blog posts, the things you put on your own website on your own domain are protected by law. For example, there are many recorded cases of Google or Facebook banning individuals and claiming that they were terrorists. Although the government can take your domain away from you too, there are few recorded cases of it. So, having a static website on your own domain is a good thing. Now the question is: what technology to use?
The are two commonly known technologies for hosting simple websites:
Wordpress
Static site generators
I will argue here that Wordpress sites should be avoided when possible. If you want to make a full webshop, so a website with a lot of dynamic content, then Wordpress is probably a good bet. However, if you website contains only static text, like this website, then a static website is a better choice. The reasoning is as follows. Essentially, a website is a server that responds to requests for information. For every site that you visit, there must be a server standing ready to take your request and give you the appropriate response. For a static website, this response is easy: give back the appropriate file for each request. For example, when you opened selfhoster.dev/static-website
, your browser actually requested https://selfhoster.dev/static-website.html
which is a HTML file which is then shown by your browser. A static site hoster such as Cloudflare, GitHub Pages, or Netlify makes hosting such sites easy. They allow you to upload a bunch of files and then they will distribute those files to a server so that they are ready when a reader requests the page. Even better, they distribute the files over multiple servers so that an Indian reader gets a copy from an server in or near India and an American gets a copy from a server in America. This makes the website load quickly for people all over the world. Furthermore, note that one server can take care of multiple websites. So, the server that you got this selfhoster.dev
page from might actually also serve example.com
or other sites. Since a big server can handle thousands of requests per second and since most sites are visited only a few times per month, you can imagine how many sites one server can host! Hundreds of thousands probably. That's why static site hosters are usually for free. It costs them almost nothing to host your website. Furthermore, the technology is very simple which makes it almost impossible to hack. You would need to hack into Netlify, Cloudflare or GitHub Pages to change someone's site.
Now what happens if you use Wordpress. Wordpress contains not only the responses to readers, but also a full system to allow you to log in, change settings, and write articles. This is terrible from a security standpoint because people can hack your Wordpress website and change your content. Furthermore, the site contains all kinds of specific logic and therefore it requires much more from the server. You can probably host a hundred to maybe a thousand Wordpress sites on one server which is much lower than the hundreds of thousands static sites that you can host on one server! This is why you always need to pay for Wordpress hosting. It requires a lot of resources.
Finally, static sites can be used together with Git. Git is the technology used by 99% of software developers worldwide to manage software. Git allows developers to keep track of changes to files and to, basically, never lose work. As it happens, Git is great to manage software and great to manage static sites because, like code, static sites are mostly a bunch of text. Wordpress on the other hand doesn't fully integrate with Git.
So, that's why I would advice to avoid Wordpress where possible. To build a static site, I would advice to use a static site generator such as Hugo. See their tutorials for more information.
Furthermore, I would advice to use a static site hoster such as Cloudflare, Netlify or GitHub Pages. Managing your own server is simply not worth it and, more importantly, it is extremely easy to switch your website from one hoster to another if that may become necessary at some point. To switch, simply send your files to another hoster and that's it 🎉.