Petr from
Knowledge.Exposed

Lorem ipsum dolor sit amet, consectetur adipiscing… Does’t this lipsum look great?

Home

Blog

About

Home

Blog

My work

About

Tags: Nginx | PHP | SQL
Published: March 4, 2022
Categories: Self-hosting | Web server

Self-hosting services is great, but not for everyone

Throughout last 15 years I’ve been hosting websites on many different hosting services. And I must say If you are having small site with few visitors than you might be able to go far with cheap solutions that are marketed from every direction. Now I come to the point where I am self-hosting my websites, webapps on network of Virtual-Priavate-Servers (VPS) and I am not planning to stop.

With power comes responsibility

If you are having your own VPS for your services you are the boss of the server. You only have what you will setup yourself. Which is great and also not so great.

You really need to take care of many things related to your server, even things that are not connected with self-hosting your websites at all. For example you need to set up a way how to connect to  your server. Secure it, keep your server updated, set up some monitoring, backups, firewall, etc. etc.

On the other hand… Do you want to be the only one who has access to some sites you’re hosting? Sure no problem! Want to have multiple sites on one VPS? No problem, just make sure your server is not getting overloaded. Need to run docker apps, python apps and PHP apps on one machine? Just use reverse proxy and you can do it all.

But… Be aware that your VPS is becoming single-point of failirue for all those services. There are ways to mitigate eventuall crash but those are beyond this series. Maybe in futre we can have look into load balancing but those are “foreign lands” even for me in this point.

When it comes to self-hosting

I am mostly working with WordPress. For my clients I am creating and managing pages that I usually host on my VPSes. Through some trial and errors I got to these tools / apps I am using:

Nginx

This fella is a webserver. We will get into it little deeper but this is the first line of accepting requests from your clients and visitors on your VPS. Based on the rules that you configure here static pages are served like html files, images, fonts, etc.

If you are having python, PHP (WordPress), or other type of apps. Nginx will forward the request where it belogs and return the result to the client.

In case you are running stand-alone docker app on your server. Nginx can also serve as reverse-proxy, let’s call it a middle-man, who will take of things like SSL, caching etc, everything else will be passed to docker and from docker back to client.

MariaDB

As name suggest, It’s a database (DB) engine. Reason that I am using MariaDB instead of MySQL is that MariaDB is fully OpenSource where MySQL is partially closed source. If you will be self-hosting your services you will inevitably get your hands on SQL databases so if you have some time to spare you can check some basic syntax.

My knowledge in database engines isn’t that great to be able to explain more, but you will need DB for your apps to store data, orders, content, user data, etc. MariaDB is working for me as well as for many many other people who are using it. If you are using different DB engine let me know in the comments. Ideally with reason why you are using it.

PHP-FPM

Going by it’s full name “PHP FastCGI Process Manager”. Nginx, on it’s own cannot interpret PHP. If you try to serve WordPress without any PHP engine your result page will just spit out content of PHP file. Literally content So you will see somehting like:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';

For this reason you need to have on your server something that will process the PHP code. In my case I am using PHP-FPM, because it allows for quite easy per-user separation of websites which improves security.

Side note: OpenLiteSpeed

Recently (March 2022) I heard about OpenLiteSpeed webserver and it’s performence espetially with WordPress. I don’t know much about it at this point but if you are eager to explore make sure to check this one.

I believe that I will have some more info about this in the future as well.

That’s about it. In next articles we will dive deeper into VPSes, self-hosting websites etc.