Migrating to a self-hosted server

March 2, 2024 - Reading time: 5 minutes

Welcome to first post on this website! I'll go through entire process of migrating a website, even though it's not that interesting (aka I just want to post something lol).

Part one: why

I've been using a rented VPS for a very long time (since 2020 I think), that was costing me about 25 zł (5,78 €/$6,28) each month to run. In December, I've bought this server, which has been running SMB and media server since then.

The decision to migrate was kinda an impulsive one, because why should I pay for a VPS when (thanks to my ISP being kind enough to allow port forwarding) I can run it at home, with a script to update Cloudflare with my IP.

So in the morning, I've finally made the decision: I'm sending a resignation for my VPS and moving everything to my home.

(screenshot is basically a resignation form)

Part two: how and "Failed to save file"

The first part went smoothly. I've compiled a custom version of nginx (I'm using ngx-fancyindex addon for my downloads section), installed PHP and php-fpm packages, moved my e-mail to a third party provider, and configured everything. At first I chose Grav for this website (ain't no way I'm having another attempt at writing my own flat file CMS, last time it went poorly, and in Javascript), so I went ahead and installed it.

But, there was a problem. It was complaining that it didn't have permission to save.

So, I made http (user who is running nginx and php-fpm) owner of website files. Nope. Then I used a script from Grav documentation to give files proper permissions. Still no. Finally, I've used a foolproof way of allowing anyone to do anything with a file, or, in other words, 777 permission. Nada. I was out of ideas on how to fix this, and I began scouring the web in hope of finding a solution. StackOverflow post one after another, and I was still trying to install.

After this, I've thought maybe there's a bug or something in Grav, so I've tried installing Bludit (which I'm running now).

Guess what error it also had.

I eventually gave up for some time, and took a nap.

I woke up and began searching for the solution again, searching for general "PHP cannot save file", and this time I actually found the solution.

Take a guess at what the issue was.

It turned out that systemd php-fpm service file mounts some directories (/usr, /boot, and /etc) as read-only.

And sure enough, checking php-fpm.service revealed that there is in fact an option which mounts these directories read-only.

So I quickly moved all files to /home/http, and everything was running perfectly.

Then I decided that I don't like Grav and moved to Bludit XD. I chose a dark theme (just looking at this white admin page hurts my eyes enough, I don't need to hurt them more by my webiste having a white theme), wrote about me page, and it's done.