
Raspberry Pi as a local server for self hosting applications - christian_fei
https://cri.dev/posts/2020-09-12-Raspberry-Pi-as-a-local-server-for-self-hosting-applications/
======
anderspitman
The hardware is there (RPi + USB storage). The server software is there
(NextCloud, Plex, n8n, etc). What isn't there is the plumbing. The next
logical step after this blog post is making your services accessible to your
phone over the public net. You'll immediately find yourself mired in domain
name registration, VPS management, TLS cert management, dyndns, port
forwarding, hole punching, etc etc.

There are lots of great tools that solve some of these problems. I have yet to
find one that solves all of them.

I think we need something like Namecheap + CloudFlare + ngrok, designed and
marketed for self-hosters and federators. You simply register a domain and run
a client tool on each of your machines that talks to a central server which
tunnels HTTPS connections securely to the clients.

Mapping X subdomain to Y port on Z machine should take a couple clicks from a
web interface.

~~~
Polylactic_acid
I tried running nextcloud on an rpi. It just doesn't cut it. I had the 4gb
model and nextcloud runs but its a horrible experience. You go on the web UI
and click a photo and it takes 10 seconds to load. Moved my server to a ryzen
5 based setup and now everything is instant. I'm not sure what the limiting
factor on the rpi was because the ram and cpu usage was low. Perhaps it was
memory or storage speed.

~~~
salawat
On SD card or USB w\UASP enclosured SSD?

~~~
magicalhippo
And if USB, make sure to test the speed. Some controllers need quirks
enabled[1] to get speed, including a lot of popular JMicron ones. Mine went
from ~20MB/s to 300MB/s for a Samsung 850 SSD.

[1]:
[https://www.raspberrypi.org/forums/viewtopic.php?t=245931](https://www.raspberrypi.org/forums/viewtopic.php?t=245931)

------
antognini
One thing to watch out for when doing something like this is that the
Raspberry Pi will by default put your file system on the SD card it boots
from. SD cards aren't meant to support a lot of write/erase cycles, so it's
easy to end up with a corrupt SD card after a few months to a year depending
on what you're doing on your Pi.

A workaround that can save you some headaches here is to only boot from the SD
card (which means you're effectively only ever reading from the card), and
then mount a filesystem on an external SSD drive. There are a couple of good
guides here [1] [2].

[1]: [https://www.stewright.me/2019/10/run-raspbian-from-a-usb-
or-...](https://www.stewright.me/2019/10/run-raspbian-from-a-usb-or-ssd-on-a-
raspberry-pi-4/)

[2]: [https://www.pragmaticlinux.com/2020/08/move-the-raspberry-
pi...](https://www.pragmaticlinux.com/2020/08/move-the-raspberry-pi-root-file-
system-to-a-usb-drive/)

~~~
jakobdabo
Most writes are the logs, I use log2ram [1], it reduces SD writes
substantially.

[1] [https://github.com/azlux/log2ram](https://github.com/azlux/log2ram)

~~~
dundarious
Or for those using journald, use Storage=volatile in
/etc/systemd/journald.conf and then `systemctl force-reload systemd-journald`.
Remove /var/log/journal to get rid of the old persisted logs.

------
fossuser
How do people access these servers off of their home network (or do they
not?).

That seems like most of the value to me, hosting some service you can access
from anywhere without having to use Digital Ocean.

It seems like most residential ISPs don't provide a static IP and some block
port 80? I think forcing ISPs to allow home users to serve traffic via some
standard method would go a long way to enabling a more decentralized web.

I know Zero Tier, and Tailscale exist - but I don't really understand how they
work (and I think they require intermediate server access anyway so might as
well use Digital Ocean?).

I'd like a future where you could sell users a raspberry pi running a service
they can just plug into their home switch and access it securely from
anywhere.

~~~
boredpenguin
> How do people access these servers off of their home network (or do they
> not?).

Wireguard, listening on the public IP with port forwarding, and using a
dynamic dns client to ensure I can always connect even if the public IP
changes.

> It seems like most residential ISPs don't provide a static IP and some block
> port 80?

Not the case here in my experience (Spain), but if you're fine being the only
one with access you only need to forward the VPN port.

> I know Zero Tier, and Tailscale exist - but I don't really understand how
> they work

I only used ZeroTier a bit, but IIRC it was something like:

1) Create a new network in the ZeroTier One website 2) Download the ZeroTier
client on your machine(s) 3) Enter the network ID 4) (optionally) authorize
the device on the web UI 5) Now the device can connect to other ZeroTier peers
on the network you created!

(So yeah, at least the "easy" way involves using their server, no need to
selfhost it). Also this option should work without port forwarding.

~~~
anderspitman
Can the ZeroTier client create a tunnel without root access? That's the
biggest weakness of WireGuard IMO. One of the things I like about ngrok is it
doesn't require root.

~~~
boredpenguin
> Can the ZeroTier client create a tunnel without root access? That's the
> biggest weakness of WireGuard IMO.

No idea about ZeroTier, but you should be able to use WireGuard without root
access using the userspace implementation in Go[0] (that's the one used in
non-rooted Android phones, Windows, and maybe the BSDs)

[0]: [https://git.zx2c4.com/wireguard-
go/about/](https://git.zx2c4.com/wireguard-go/about/)

~~~
anderspitman
I tried wireguard-go and it required root to create a tunnel. I wonder if it
would be possible to adapt it to forward to a local port rather than mapping
directly to a network interface.

------
liability
I recently thought about getting an RPi4 but ultimately spent about a hundred
dollars more to get a cheap NUC. It was a bit more expensive but it seems like
a more robust platform. A real AC adapter instead of USB (apparently the RPi4
kind of botched it in some revisions? What I read wasn't confidence
inspiring), takes normal SO-DIMM ram and a typical SSD, doesn't have a
reputation for overheating.. it seems generally more straight forward with
fewer 'gotchas.'

~~~
tyingq
If you have an i5 or i7, you may also have the advantage of remote KVM (via
Intel's vPro) so that you can revive it remotely if needed.

~~~
entropicdrifter
Not to mention the built-in advantage of Intel's much better supported
QuickSync video encode/decode if you're doing any sort of media streaming.

~~~
Waterfall
Won't matter if your main computer does the decoding, and for the price of one
good computer that can stream to all devices including crappy ones versus all
good ones and a cheap NAS to host, which would you choose?

~~~
rovr138
Guess the question then becomes, do you need transcoding on the device
streaming?

------
erulabs
Nice! I recently wrote a blog article about home-hosting on a RPI4 using
kubernetes ([https://kubesail.com/blog/k3s-raspberry-
pi](https://kubesail.com/blog/k3s-raspberry-pi)).

Such a bright future in home-hosting - really looking forward to seeing the
movement grow! The [https://www.linuxserver.io/](https://www.linuxserver.io/)
community is pretty great re: home-hosting apps as well.

~~~
christian_fei
That's awesome! didn't know about
[https://fleet.linuxserver.io/](https://fleet.linuxserver.io/) !

Gotta definitely try this, thanks

~~~
erulabs
Yeah! They have a really great community in their chatroom as well - A lot of
our Kubernetes templates are based on their excellent Docker images :)

------
louwrentius
If you run anything semi-serious please consult this blog post by Jeff
Geerling about SD card performance (buy A1 ones).

[https://www.jeffgeerling.com/blog/2019/raspberry-pi-
microsd-...](https://www.jeffgeerling.com/blog/2019/raspberry-pi-microsd-card-
performance-comparison-2019)

~~~
sneak
It’s an rpi connected to a dual core laptop on a home connection, presumably
without a battery backup. Nothing about this is remotely semi-serious.

------
codezero
I haven't been into computer hardware lately, but I decided to pick up a NAS,
and was pleased to learn that they're now just a complete computer - I've
started using VMs living on my NAS to do this kind of thing, which is quite
nice. Synology's interface is not bad either, but I imagine others have come
up with even better ways to use these systems.

Obviously a RPi is a way cheaper way to get a lot of the same work done though
:)

------
rcarmo
Friendly reminder that you can use Piku
([https://github.com/piku](https://github.com/piku)) for Heroku-like
deployments.

~~~
benbristow
I see it's inspired by Dokku (because Dokku doesn't support ARM). I use that
for a few of my apps on a VPS, nice tool.

[http://dokku.viewdocs.io/dokku/](http://dokku.viewdocs.io/dokku/)

------
nicbou
I'm using my old Thinkpad T510 as a home server. It's been running for 7+
years already. I only need to dust the vents once in a while.

It has PiHole, Nextcloud, my humble little Netflix clone, and a few other
things. If you use ffmpeg a lot, you ought to have more power than the RPi
offers. I often SSH into it to use it as a SOCKS proxy in other countries.

~~~
phil21
Yep, older laptops make perfect home servers/routers. Built in "KVM switch",
built-in UPS, low power/noise, etc.

Before I switched to Ubiquiti I ran pfsense on a VM on my old 410s for many
years, among other virtual machines for home lab use.

~~~
IanSanders
>low power/noise

how does that compare to RPI?

~~~
nicbou
It's a regular laptop fan, so it's inaudible unless ffmpeg is converting a
movie. Then there's an audible hum, but it's no louder than the fridge's
compressor.

------
cstuder
On my Raspberry Pi 3 I'm running Hypriot OS which installs a minimal host OS
and then just runs Docker.

Thanks to cloud-init (Old version though) you can even pre-configure the boot
image with your SSH key etc. which allows you to automate your initial
install.

[https://blog.hypriot.com/downloads/](https://blog.hypriot.com/downloads/)

[https://cloudinit.readthedocs.io/en/0.7.9/topics/capabilitie...](https://cloudinit.readthedocs.io/en/0.7.9/topics/capabilities.html)

~~~
christian_fei
that is interesting, thanks!

sounds like a super smooth dev and deploy experience

~~~
Polylactic_acid
Docker on ARM is not a smooth experience. Hardly anyone builds containers for
ARM so you end up either building everything yourself or finding weird -arm
versions of popular containers.

~~~
christian_fei
have you seen this?
[https://hub.docker.com/u/arm32v7](https://hub.docker.com/u/arm32v7)

------
_lacroix
Setting up a pi-hole DNS server for my wifi network was one of the best
decisions I've ever made. Horrifying to see what percentage of traffic is on
the ad server blacklist though...

~~~
h4l0
I wasn't aware that my Samsung Smart TV had been logging almost my every
action on the TV until I set up a PiHole server. Also, my respect for Apple
grew by the fact that only device that wasn't doing loads of telemetry turned
out to be my Macbook in the whole household.

~~~
outworlder
> Also, my respect for Apple grew by the fact that only device that wasn't
> doing loads of telemetry turned out to be my Macbook in the whole household

Turns out that modern electronic devices are expensive. If you are not charged
up-front, there's a good chance that you are being charged in some other way.

~~~
t-writescode
Let’s be fair, even if you did pay more up front, they’d still get ads from
you. The whole thing is pervasive and we need legislation for it.

------
x87678r
I like my rpi but my life got better when I bought a mini pc instead. Its
pretty common to get a 16GB mem micro for not much more than an rpi with power
supply, sd card, case.

[https://computers.woot.com/offers/lenovo-
thinkcentre-m73-240...](https://computers.woot.com/offers/lenovo-
thinkcentre-m73-240g-tiny-pc-10?ref=w_cnt_lnd_cat_pc_2_24)

~~~
gramakri
Yup, similar. I have a thinkcenter m600 series. Quite old but works really
well.

~~~
flipbrad
I looked at these but got an old ThinkPad laptop instead. Integrated UPS,
keyboard and mouse...

------
flyinghamster
It really wasn't until I got myself a Pi 4 that I really appreciated what an
improvement it was over the earlier generations. I have the Pi 4 and a 3B+
running BOINC, crunching away on World Community Grid[1], and the 4 is at
least twice as fast at completing work units (it's too early for RAC numbers
to settle down, yet). The Cortex-A72 is a huge step up from the A53. [ETA:
both are actively cooled.]

Also, the Pi 4 eliminates the USB2 bottleneck the old Pis have, and has a
couple of USB3 ports.

[1] Be sure to boot with arm_64bit=1 in config.txt or you will get no work
units.

~~~
christian_fei
Thanks for the hint! Will include this in my config.txt

------
oblib
A DigitalOcean vps can be a pretty inexpensive and easy option.

I've done this with a Pi and Dyndns. It's pretty easy to setup but not as good
(for me) as a DO vps because my home ISP limits data heading out. I would have
to purchase a business plan to fix that and it still wouldn't be better or
cheaper than what DO and others can provide.

A Pi can be used for development on your home network and it excels at that.
And the older RPis can run [1]CouchDB and be configured to "Live Sync" with a
CouchDB running on a commercial VPS. That too is a pretty easy to setup and it
provides some pretty nice options. For example, you can make your app use the
Cloud based CouchDB while you're out and about and it will sync your data with
your local CouchDB. Then when you get home you can turn off the cloud access
and even delete your data on the cloud DB.

1\. The latest version of CoudhDB (v3.0+) doesn't run on the new ARM based Pi
4.

~~~
christian_fei
yep, noticed the same. a lot of containers are not available for arm, and thus
you'll need to build them yourself..

------
yegle
For anyone with a home server and has the need to remotely access your self-
hosted websites, [https://pomerium.io](https://pomerium.io) has been a
wonderful piece of software in my stack.

You can safely expose your self-hosted websites to the internet and without
the hassle of needing to have a VPN connection first.

~~~
christian_fei
that's cool!

------
StillBored
The pi4 even overclocked isn't a great number cruncher, and I don't think the
gpu acceleration has landed yet..

So I might expect it to be on par with that old of a macbook but not beat it
by nearly 2x, particularly if the macbook is being accelerated. (despite
having 2x the core count) Which makes me think the MBP may be suffering from
some serious thermal throttling, which wouldn't be uncommon on machines of
that vintage.

I also assume the call line is:

[https://github.com/christian-fei/raspberry-pi-time-
lapse/blo...](https://github.com/christian-fei/raspberry-pi-time-
lapse/blob/master/create-time-lapse#L17)

which is noticeably missing the -hwaccel switch, which means its probably not
using the GPU on the mac..

~~~
christian_fei
Definitely, good points. Gotta try your suggestion regarding the missing flag
on the ffmpeg side and report back, out of interest. I’m on service battery
since a long time in fact I consider this setup only temporary, and will soon
upgrade to a modern machine

~~~
ed25519FUUU
Set the encoder to omx on the pi as well to take advantage of accelerated h264
encoding.

~~~
christian_fei
will try!

------
newbie789
This is related because I'm exclusively interested in building a local-
network-only media server to serve my firestick and a laptop, but are plex
(nice interface, for some reason requires a sign-in to their service, some
sort of paid features) or emby (similar) the only options?

If I for example wanted to just access my media library through firestick and
windows with a kinda neat interface without paying anybody or making an
account on a third party website, is there a solution?

I suppose I could just use VLC, which is fantastic software that isn't
particularly beautiful and get used to it, but I'd like a somewhat more
"netflix-style" interface for navigating my content within a single rpi server
on my network.

~~~
nonninz
It seems that Kodi[1] would be your perfect choice, and that is indeed what
I'm using in a very similar setup.

Setup your media (local or remote) library, and the scraper will enrich it
with posters, synopsis, actors, etc.

[1] [https://kodi.tv/](https://kodi.tv/)

~~~
newbie789
Thanks for the suggestion, I'll have to give that another try!

I've had success with Kodi in the past with my laptop but I've also had big
performance issues on the firestick. To be fair, it's been a couple years
since I tried that so I'll see if the newer versions perform better.

------
gramakri
I have tinkered with RPI a lot in my previous life, I used to maintain the Qt
eglfs QPA plugin. Back then, they were quite under powered CPU wise. Are the
recent versions powerful enough to host websites and data for every day use?
Like say, is it powerful to host a website, couple of blogs, a
nextcloud/syncthing instance and say Emby/Jellyfin/Plex? Most importantly, I
want to hear about setups that people are using for every day use and not just
learning.

(For context, we get a lot of requests to port Cloudron to ARM/RPI but I am
still not sure if these are just hobbyists/tinkerers or something people use
everyday.)

~~~
christian_fei
Using Emby actively right now and it’s working like a charm! Nextcloud will
probably be my next experiment

~~~
gramakri
Does hardware transcoding work?

~~~
christian_fei
wouldn't know. installed it through a .deb file, so it's certainly better
suited to use the hardware than through docker probably

------
sneak
Note that if you got all excited about n8n when learning about it from this
webpage, as a potential open source Zapier:

n8n is not open source, despite being source available. The author goes to
pretty great lengths to avoid confronting this fact.

[https://github.com/n8n-io/n8n/issues/40](https://github.com/n8n-io/n8n/issues/40)

~~~
justin66
Wow. I'm instantly sympathetic with the author given the level of vicious
fanaticism he was confronting there.

~~~
sneak
Drew being mean doesn’t change the fact that the author was (and to some
extent still is) being shady.

------
valiant-comma
For simple, web-based speedtests on a local LAN/WLAN, I like librespeed[1].
Really helps identify subpar WiFi coverage (for example), better than just
signal strength. Runs nicely on a Pi, up to line rate (1 Gbps) on a Pi 4.

[1]
[https://github.com/librespeed/speedtest](https://github.com/librespeed/speedtest)

~~~
christian_fei
awesome! thank you!

------
gcctrp
There are FreedomBox versions for Raspberry Pi 2, 3B, 3B+, and 4B.

[https://wiki.debian.org/FreedomBox/Hardware#Also_Working_Har...](https://wiki.debian.org/FreedomBox/Hardware#Also_Working_Hardware)

------
dboreham
Ime devices with a proper CPU and SSD such as Intel NUC and Beelink are the MV
solution to run server software without constant headaches due to slowness,
limited memory and flash wearout. Ymmv of course. The Pi4 with 8G is getting
close.

------
KingFelix
I have a RP4 on my desk collecting dust, need to get it up and running for
something useful. This post has got me motivated to find a use for it.

~~~
chrisdalke
My favorite use of a Raspberry Pi has been to run a Jenkins instance.

I use it for CI/CD on projects, but also for automating other tasks -- You can
use Jenkins to wrap any arbitrary script with more higher-level logic and
extensibility than a cron job.

For example, I use Jenkins to automate multiplatform builds for some side
projects, to periodically ingest data into a database, perform cleanup jobs,
etc.

~~~
christian_fei
That’s nice! Trying out n8n.io right now and it’s pretty sweet

------
noncoml
My only gripe about Raspberry Pi, and only thing that prevents me from using
it as a home server, is that the USB cannot power an external HD

~~~
flyingcircus3
I've wanted to make a headless audio player for my car, and this power issue
has been the bottleneck for me. Additionally, spinning disks and moving cars
are a bad combination.

Just last week I bought a 500gb SSD and usb adapter for about $75. My Pi 2
powers it without issue. The only problem I see is that the SSD can get fairly
warm, so keeping it in my closed center console probably isn't a good idea.

------
ttflee
For ffmpeg h.264 encoding on macOS it is not very wise to use x264 instead of
h264_videotoolbox.

------
2Gkashmiri
How does Cgnat fit into this? Or do we have to forego any hopes of it as long
as cgnat exists?

------
gurjeet
Does anyone have any experience with running and upgrading FreedomBox for
self-hosting.

------
pettycashstash2
i use the rasp pi 3+B 1 GB model to sense oil level in my oil tank. i now know
oil tank level anywhere any time. Take a look at
[http://myoilguage.com/](http://myoilguage.com/)

~~~
christian_fei
that's interesting!

------
tonitosou
i use a pi as webserver. works like a charm

~~~
christian_fei
Nice!

------
sneak
This is probably way better achieved by a $5/mo VPS.

Benefits:

\- way faster

\- always on (presumably battery backed)

\- you're not responsible for disk or hw failures

\- better internet (faster, redundant connections)

\- cheaper ($60/year vs $100 upfront)

\- not fighting architecture differences

\- comes with a public v4 address

\- usually comes with a v6 address too

Downsides:

\- data isn't under your control and is subject to military espionage

\- your internet connection to move larger files to/from the remote device may
not be great

~~~
tga
$60/year is not cheaper than $100 one time, unless you plan to run the RPi for
one year and then throw it away.

~~~
novok
You do pay for the electricity cost. Assuming the Rpi consumes 10W and is on
24/7 and your electricity cost is $0.15/kwhr : 365d * 24h * 0.01kW * $0.15 =
$13.14/yr in electric costs.

