A practical guide on how to host your own services without having to spend much money
A little backstory
When I was a kid I had a lot of problems with deploying my projects to make them accessible through the web. That's one of the reasons why I developed an interest for p2p networking.
Before I would use heroku(2021-2022) to deploy my Go projects until they stopped offering free hosting for simple projects. After that I started to plan on some weird ways in which I could deploy my projects and they were a mess. I was young and I didn't had much money. Tho I had enough money to buy snacks and other stuff.
That's when Cloudflare comes. You just need to spend less than a snack in a domain that you are willing to pay. And after that you don't need to do much.
what you need
- Cloudflare(domain, zero trust & cloudflared)
- Golang
- SHP
- git
- A computer with Linux(any distro is fine, but I would personally recommend lubuntu)
cloudflare
Obviously you will need to create an account and do other things on cloudflare, for that you can find many videos. I would probably recommend this one:
self hosting platform
But that's not enough, this only works for you expose a port to the public but it doesn't helps with the services to stay up, or deploys your services. For that you would need to know how to use systemd or just avoid doing that, setup a simple service of SHP and just enter into the dashboard and do your own things.
SHP simplifies the process of deploying your services and keeping them up without having to configure any service file after SHPhas been properly deployed. You can also expose it to the public network so you could access it at any part of the world, but if you do that I would ensure to have a very good password.
steps
Install and configure Golang for that you just need to add that to the
PATHclone the project executing this command
git clone https://github.com/ranon-rat/self-hosting-platform.gitWhenever you have installed
SHPremember to create a file named.env.local. It should look like thisPASSWORD=<create a strong password dont be dumb> PORT=1234 # you can specify any port, thats up to youCreate a service file. You need to create the file in this directory
/etc/systemd/system/Here is an example of how the file must look like:# lets name the file self-hosting-platform.service if you name it as anything else, you will have to execute different commands. [Unit] Description=Self Hosting Platform Go Service After=network.target [Service] Type=simple User=<your user> # you must specify where you have installed the shp directory WorkingDirectory=<pwd to your file> # Variables básicas Environment="HOME=/home/<your user>" Environment="USER=<your user>" # I usually install the golang binary in my user home but thats up to you. Environment="PATH=/home/<your user>/go/bin:/usr/local/go/bin:/usr/bin:/bin:/usr/sbin:/sbin" # Cargar .bashrc antes de ejecutar ExecStartPre=/bin/bash -c 'source /home/<your user>/.bashrc' ExecStart=/usr/bin/env go run main.go Restart=on-failure RestartSec=10 StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.targetExecute the finishing commands
# you must reload the daemon first systemctl --user daemon-reload # this will make it autostart when the system begins systemctl --user enable self-hosting-platform.service # This will immediatly start the service systemctl --user start self-hosting-platform.service # This will just tell you the current status of the service :) systemctl --user status self-hosting-platform.service