<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yuriy Pankiv on Medium]]></title>
        <description><![CDATA[Stories by Yuriy Pankiv on Medium]]></description>
        <link>https://medium.com/@yuriypankiv?source=rss-db91afbace62------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hddEBKK_Py5AVzH_.</url>
            <title>Stories by Yuriy Pankiv on Medium</title>
            <link>https://medium.com/@yuriypankiv?source=rss-db91afbace62------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:47:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yuriypankiv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Self-hosted website]]></title>
            <link>https://medium.com/@yuriypankiv/self-hosted-website-b22502d1414d?source=rss-db91afbace62------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22502d1414d</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[self-hosted]]></category>
            <dc:creator><![CDATA[Yuriy Pankiv]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 23:08:08 GMT</pubDate>
            <atom:updated>2026-03-02T14:05:10.483Z</atom:updated>
            <content:encoded><![CDATA[<h3>Self-hosted website on a Raspberry PI</h3><h3>TL;DR</h3><p>In this article I will:</p><ul><li>Share my reason on why would you might want to self-host your application.</li><li>What would you need to think about if you want to do it.</li><li>Show you how I have approached this.</li></ul><h3>Main idea</h3><p>I’m an experienced developer, that has developed plenty of different websites. I’ve did small 1-developer projects and enterprise-level ones.</p><p>Every one of them had their own way to host their app. Because there is no silver bullet. You can approach this in many different ways.</p><p>I’ve worked with great DevOps engineers that have configured pipelines to build a project, I’ve done some configuring on my own. I had a mixed approach, where we were working together to make our app work.</p><p>There are few ways you can approach this task:</p><h4>Platform as a Service — “Highly-managed approach”</h4><p>You can take the road of “highly-managed approach” and use tools like Next.js, Heroku or similar ones. A lot of stuff is automatically managed for you. CI/CD integration, custom domain, caching and so on. This might be perfect for you, as it abstracts a lot of complexity.</p><p>The selling point of those is that you think more about the app and less about the infrastructure.</p><p>Overall, this takes a lot of load off your shoulders and is a go-to if you need to quickly get something up-and-running and might want to scale it later.</p><h4>Infrastructure as a Service — “Cloud hosted approach”</h4><p>You can go more “manual”, rent a server for your needs. Like, rent an AWS EC2 instance (or alternatives on Google cloud, Microsoft Azure, Hetzner and so on). You manage some settings on your own, but cloud providers still cover significant portion by themselves. Also, you have a plenty of supporting tools to use along the way that help with deployments, domains, DBs, caching and other stuff.</p><p>When you know what you need — you can choose this approach, as it gives you more control. Usually, it’ll be more price-precise, you’ll pay per resources/usage, rather than a plan.</p><p>Even though, this approach can be great or both small personal projects and large enterprise-level companies, I’d it’s better suited for the latter.</p><h4>“Self hosted approach”</h4><p>And here it is, a self-hosted approach. There are no standard approaches, but there are common things that you need to cover to make it work.</p><h3>My motivation to choose self-hosted approach this time</h3><p>I’ve tried other approaches, but I’ve been avoiding a self-hosting one for quite some time. I’ve been hiding behind abstractions that were given to me by cloud providers. Or I had no need to research those on my own, because configuration was done by someone else.</p><p>But no more. I want to learn and understand how things actually work. And the idea to have my own tiny web server sitting besides me on the desk is really thrilling.</p><p><strong><em>NOTE: This is my personal experience and my own findings. My main focus was on learning (as I’ve investigated a lot of possible solutions to one given problem). And there are indeed a lot of ways to solve a task. Here is how my personal journey looked like and solutions that fit my needs.</em></strong></p><h3>Preparation</h3><p>Before starting the actual setup steps, here is what I’ve decided to use to make this project happen:</p><h4>Hardware</h4><p>Raspberry PI 5 + PI Cooler. This is a general-purpose computer. May not be the most optimized hardware for this, but it is fairly universal, so it fits me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ZPH4K3XXabsz_hrj.jpg" /></figure><h4>Domain</h4><p>I bought a domain on Cloudflare. There are plenty of tutorials how to do it. You can choose any other registrar, up to you.</p><h3>Implementation</h3><p>There would be 3 “milestones” that I’ve decided to separate. I’ve split those based on significant upgrades in the usage of your self-hosted solution.</p><h4>The first milestone — Have something shown in your browser</h4><p><strong>Configure your hardware</strong></p><p>First of all, prepare your work environment. For me it was to follow a Raspberry PI official documentation setup. After that, you should be able to SSH into your PI and invoke some commands there.</p><p>Then, make sure that your system us up-to-date, all required packages for your work are installed (In my case, I had Debian).</p><pre>sudo apt upgrade<br>sudo apt update</pre><p>I’ve used Node (through NVM), Git and other stuff. Google how to install it, this step is very straightforward.</p><p><strong>Configure your software</strong></p><p>Since you have your tools configured, now we need some code to run. I’ll describe how I got my code to the Raspberry PI a bit later, but for now consider adding some boilerplate code for the sake of making everything run.</p><p>I’ve used <a href="https://vite.dev/guide">React + TS + Vite template</a>.</p><pre>npm create vite@latest</pre><p>Go to your project folder, install packages and start your server.</p><p>You should be getting your app working on port 5173.</p><p>If you check your browser, you should see your page at the <a href="http://raspberrypi.local:5173/">http://raspberrypi.local:5173/</a></p><h4>The second milestone — <strong>Have something shown through public URL</strong></h4><p><strong>Cloudflare Tunnel</strong></p><p>That’s great, the app is running locally, but you won’t be able to share this link with friends at the moment. It’s your local link. It is visible for you, because you are using your “private network”. Your devices used private IP addresses (which are within your home network) to communicate. So you are able to see this page from your computer.</p><p>You want to have your Raspberry PI to be internet facing. To make it work, you need to make it have a public IP.</p><p>To do such thing, I’ve used Cloudflare Tunnel. It allows my to bypass all the configuration steps as it establishes outbound connections between your origin web server and the Cloudflare global network.</p><p>To do so, register a Cloudflare account, and go to Zero Trust cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*a8Sf36Me80MINyEbX0v1lg.png" /></figure><p>Then go to Networks &gt; Tunnels section and create one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*qDTe53a318rWw0NdCVFFyw.png" /></figure><p>Create a tunnel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*4Xh9QNxM1IsYYcE_QDocQQ.png" /></figure><p>Choose a corresponding options to install it on your device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPUn194vQAF3SJDZenFvqA.png" /></figure><p>After all the steps are done, you can add your domain here and a port where it should be pointing.</p><p>testdomain.com should point to http://localhost:&lt;your_port&gt; on Raspberry PI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AAvUJtJ3Z3IYNVuB3T93g.png" /></figure><p>Now you should have your URL working and you would be able to share this link with your friends.</p><h4>The third milestone — Have your website shown through public URL</h4><p><strong>Nginx<br></strong><em>Note: You may not need this step if you don’t need 2 URLs. Feel free to skip it.</em></p><p>I wanted to have 2 links to be serviceable:</p><ul><li>mydomain.com — where I’d serve frontend application.</li><li>api.mydomain.com — where my backend would sit.</li></ul><p>I can make my tunnel configuration be very specific: Ask it to redirect each URL to corresponding localhost port, but I’ve decided to get more leverage and control on my side.</p><p>Nginx allows me to make Cloudflare Tunnel send all requests from all links (like mydomain.com and api.mydomain.com) to http:localhost . And Nginx itself, manages all routed by itself.</p><p>To install Nginx do following:</p><ul><li>sudo apt install nginx -y— installs Nginx on your machine</li><li>sudo nano /etc/nginx/sites-available/default — go to your nginx config file</li><li>Add the following config (replace some values in &lt; &gt;)</li></ul><pre>server {<br>        listen 80;<br><br>        root /home/&lt;path_to_folder_where_index.html_sits&gt;;<br>        index index.html;<br><br>        server_name &lt;yourdomain.com&gt;;<br><br>        location / {<br>                try_files $uri /index.html =404;<br>        }<br><br>        location /api/ {<br>                return 403;<br>        }<br>}<br><br>server {<br>        listen 80;<br><br>        server_name api.&lt;yourdomain.com&gt;;<br><br>        location / {<br>                add_header &#39;Access-Control-Allow-Origin&#39; &#39;https://&lt;yourdomain.com&gt;&#39; always;<br>                add_header &#39;Access-Control-Allow-Credentials&#39; &#39;true&#39; always;<br>                add_header &#39;Access-Control-Allow-Methods&#39; &#39;GET, POST, OPTIONS, DELETE, PUT&#39; always;<br>                                add_header &#39;Access-Control-Allow-Headers&#39; &#39;Origin, Authorization, Content-Type, Accept&#39; always;<br><br>                if ($request_method = OPTIONS) {<br>                        add_header &#39;Access-Control-Allow-Origin&#39; &#39;https://&lt;yourdomain.com&gt;&#39; always;<br>                        add_header &#39;Access-Control-Allow-Credentials&#39; &#39;true&#39; always;<br>                        add_header &#39;Access-Control-Allow-Methods&#39; &#39;GET, POST, OPTIONS, DELETE, PUT&#39; always;<br>                        add_header &#39;Access-Control-Allow-Headers&#39; &#39;Origin, Authorization, Content-Type, Accept&#39; always;<br>                        add_header &#39;Content-Length&#39; 0 always;<br>                        add_header &#39;Content-Type&#39; &#39;text/plain; charset=UTF-8&#39; always;<br>                        return 204;<br>                }<br><br>                proxy_pass http://localhost:&lt;your port where backend runs&gt;;<br>                proxy_set_header Host $host;<br>                proxy_set_header X-Real-IP $remote_addr;<br>                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>                proxy_set_header X-Forwarded-Photo $scheme;<br>        }<br>}</pre><ul><li>sudo nginx -t — test if your config is valid</li><li>sudo systemd restart nginx — restart Nginx process</li></ul><p><strong>pm2</strong></p><p>If you type npm run start — your app should work fine. But if you close your console — backend stops running and you would not see anything on your site.</p><p>To continuously run your backend code as a process, you need some kind of process runner.</p><p>It “launches” your command and makes it run in the background.</p><p>I’ve used <a href="https://pm2.keymetrics.io/docs/usage/quick-start/">PM2</a>.</p><p>Useful commands:</p><ul><li>pm2 start --name YourAppName npm — — start — launches your npm run start command as a process.</li><li>pm2 delete YourAppName — deletes your process.</li><li>pm2 list — checks current processes.</li><li>pm2 logs — opens logs.</li></ul><p><strong>Github Actions</strong></p><p>To update your code on an instance, you could do few things.</p><ul><li>Manually SSH into instance, update code on your own.</li><li>Use software PuTTY (SSH) or Cyberduck (SFTP) to change/edit files.</li><li>Automatically update code from a git repo.</li></ul><p>And there are other options.</p><p>You are free to explore any of those as you’d like, but I’ve went with GitHub Actions route. There is a feature that allows you to use your hardware as a GitHub Actions Runner.</p><p>Go to settings of your project, go to Actions &gt; Runners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*yUCj1vihsSFLtw8SlEvSrg.png" /></figure><p>Go through all configuration steps.</p><p>And voila! You can write a very simple workflow, like this:</p><pre>name: Raspberry Pi<br><br>on:<br>  workflow_dispatch: # Allows manual trigger<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  ssh-to-pi:<br>    runs-on: self-hosted<br><br>    steps:<br>      - name: Checkout repository<br>        uses: actions/checkout@v4<br><br>      - name: Run a one-line script<br>        run: |<br>          echo Hello raspberry</pre><p>You would need to add some code to copy files from “work directory” of a runner to the place, where your code actually sits, but this varies quite a lot depending on your configuration. But you can use rsync command (rsync -av -q -i — delete — exclude=’.git’ . ~/&lt;your folder&gt;).</p><h3>Result</h3><p>You should have your minimal self-hosted server running, with separate URLs for your frontend and backend + CI/CD pipeline configured. After that — you are free to roam and go to any direction you might need. For example, I’ve additionally installed PostgreSQL on my PI to have a local database.</p><p>I hope it helps you or at least gives you a direction on your journey to self-host a website!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22502d1414d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>