DEV Community

Cover image for How I self-hosted my Flask app on an old laptop for almost free
Zeyrian Faris
Zeyrian Faris

Posted on

How I self-hosted my Flask app on an old laptop for almost free

I recently built fourpointo, a Flask web app for polytechnic students to manage assignments. Once it was working locally, I needed to get it live without paying for cloud hosting every month.

Then I realised I had an old, unused laptop which I was trying to find a purpose for. I figured it would be great to use it as a home server to host my website and it saves costs.

I wiped the laptop and went with Ubuntu Server since it's lightweight and widely used. There's plenty of documentation if I got stuck.

I then cloned fourpointo from my new laptop onto my server.

When developing fourpointo, I used Python's Flask library. However, Flask's built-in server is single-threaded and not designed to handle multiple requests at once. Gunicorn is a production-grade server that runs multiple workers so it can handle real traffic.

After installing Gunicorn, I got the domain fourpointo.app from Namecheap which serves as the URL for my app.

I then used Cloudflare Tunnel because it routes traffic through Cloudflare's servers, so my home IP stays hidden rather than being exposed publicly.

One issue I ran into was fourpointo going down every time I closed the lid of my server. Then I realised the server cannot go to sleep, even if the lid is closed. So I edited a systemd script using the Command Line Interface to set it so that it doesn't go to sleep when the lid is closed.

Another issue I faced was fixing bugs and pushing updates remotely. In order to update fourpointo, I needed to SSH into the server. However, that only worked if I was on the same wifi as my server. So remote fixing was impossible. To solve this issue, I used Tailscale which acts as a bridge between my server and my laptop. Tailscale generated an IP for me to use when I want to SSH into the server remotely.

Through this experience, I learnt the basics of server and network administration using Linux. I will continue to push updates to fourpointo to enhance users' experiences and hopefully in the future, I will be able to scale the app up.

Top comments (0)