A minimal DIY personal WebDAV cloud storage

Table of Contents

Preface

First, I'm a complete amateur. I had close to zero knowledge of how to execute this. I did my research to simply understand whether this was possible and just went with whatever people on the Internet were suggesting. So bear in mind, the terminology I use in this guide can be wrong. And the tools can be not the best fit for the task.

This project was done:

  • out of pure curiosity
  • at some point, it became too annoying to have to search for the music I wanted to listen to via all the variety of sources: YouTube, Spotify, SoundCloud, Bandcamp, etc.

I have a relatively big music collection. It dates back to my teenage years. So there's a lot of stuff. Pirated, bought, ripped. But I now own these files and the only issue was that they are on one of my external HDDs. At some point, I had to move it there, because it was over 500GB already. And laptops back then had 128GB or 256GB of storage by default. I had to leave my desktop behind when I started to move frequently, so the choice was obvious — to get an external HDD and move my collection there. 1TB ended up being enough for this. So, while I could just plug it in any time I wanted, it was cumbersome — it's encrypted, I had to launch VeraCrypt, pick the volume, use the password. And I didn't like the idea of having this HDD being connected all the time, because the laptop stopped being portable.

Why not a streaming service?

The only place I buy music at is Bandcamp. I purchase it once and it's mine. I can download it or listen to it online. And the artist makes more there, than on Spotify, for example. And to be frank, I really don't like subscriptions. The very idea of a subscription is just not my cup of tea. Especially when we talk about media streaming. I don't listen to music a lot. It's maybe several times a week, for 1 hour at most. So, financially, I don't see a point in paying for being able to occasionally listen to something. For some people, it's simply a question of convenience — it's easier to pay without having to manage your source of any kind. But I prefer to do this myself. And there's already so much that has been said about how different streaming services fucking over their clients in so many ways, that I don't see a point in going over it here again. To sum up — fuck steaming services, I don't mind investing some amount of my time and money to have a solution that allows me not to get attached to any kind of service.

Why WebDAV?

It's my personal opinion that WebDAV is one of the most popular ways to have online storage. I saw this option being available too many times to ignore it. I think you can find all kinds of apps on different platforms that offer WebDAV as an option to access your data. On iOS, I have a music player that offers a WebDAV connection. So, that was another reason to dig into this direction.

Setup

Hardware

  • Raspberry Pi 5 8GB
  • microSD 128GB
  • Pimoroni NVMe Base for Raspberry Pi 5
  • Samsung 980 1TB NVMe M.2 SSD

All in all, I spent around €200, and half of it was for SSD. A yearly payment for a 1TB online storage is around $80. So this setup is gonna pay off in 2.5 years.

You can go with whatever RAM and storage size you need. You can even try to use just the microSD instead of the SSD. But this setup was formed by reading all the stuff I found onine. Powerful and reliable enough to work as a server for occasional usage. Maybe I could get away with a less powerful Pi, but as an amateur I preferred to be on the safe side. I also bought a modular acrylic case that protects the top and the bottom of the whole thing, but this depends on your use case. And for passive cooling, I also got a heatsink, which, in my opinion, greatly lowered the temperature by 12 °C.

OS

I use Ubuntu Server edition. I access the Pi via my local network, it doesn't have a monitor or keyboard connected. It is connected by a wire to my home router simply for power consumption reasons. No need to have it on Wi-Fi, when it sits right next to the router.

I don't cover the OS installation here. Just look it up. It's fairly easy. And you can create a user for the ssh access as part of the installation process. When you connect your Pi to the router, just check the router's network clients and you'll see your Pi's IP address.

WebDAV

I'm using Apache. Simply because I found it the easiest to set up. After I was done with the whole thing, I was told that a more lightweight solution would be sftpgo + caddy, but at this point I was completely satisfied with the result and didn't want to redo anything.

So, let's set up Apache with WebDAV enabled.

sudo apt install apache2

# Enable WebDAV module

sudo a2enmod dav
sudo a2enmod dav_fs

# Create the directory for WebDAV
# I went with an explicit name implying it's gonna be an nvme storage

sudo mkdir /media/nvme

# Set the owner and the group of the directory to apache’s user and group,
# granting permission to www-data

sudo chown www-data:www-data /media/nvme

After you connect the SSD via the NVMe hat, it should simply become available.

lsblk

# nvme0n1     259:0    0 931.5G  0 disk 
# └─nvme0n1p1 259:1    0 931.5G  0 part

# Mount it to /media/nvme

sudo mount /dev/nvme0n1p1 /media/nvme

Now here I faced an issue when the SSD wouldn't automount. I'm not sure what's up there, and I'm too lazy to try to resolve it. Any time my Pi resets, I just have to mount it manually. Not big of a deal. So far, I had to do it only once.

Prepare the certificates for SSL support. A little annoyance with this setup is that any app you use to connect to your WebDAV will ask you if you trust this certificate, because it's self-signed.

sudo a2enmod ssl
sudo systemctl restart apache2
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

Configure the Apache host:

sudo nano /etc/apache2/sites-available/000-default.conf

Update this file with this content:

<VurtualHost *:443>
  SSLEngine on
  SSLProxyEngine on
  SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
  SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
  
  Alias /webdav /media/nvme
  
  <Location /webdav>
    DAV on
    AuthType Basic
    AuthName "WebDAV"
    AuthUserFile /etc/apache2/webdav.users
    Require valid-user
  </Location>
</VirtualHost>

Create a user for your WebDAV:

sudo htpasswd -c /etc/apache2/webdav.users your_username

Going online

To actually make this whole thing useful, you need to make it accessible from the Internet.

There's a thing called Dynamic DNS or DDNS. It simply connects an online url with your self-hosted thing. And for this to work there are two parts:

  • the DDNS service
  • your router settings
DDNS

As a DDNS provider, I used DuckDNS. I've been advised to use myaddr.io or dynv6.com, but so far I haven't had any issues with DuckDNS.

So, go to DuckDNS and sign in. Create yourself a subdomain with some obscure name, so it's not easy to find. After all, your cloud storage will be exposed to the whole Internet. Then create a file ./duckdns/duck.sh with the following content:

echo url="https://www.duckdns.org/update?domains={CUSTOMDOMAIN}&token={ACCOUNT_TOKEN}&ip=" | curl -k -o duck.log -K -

And to automate this script, so it keeps the DDNS pointing to your IP, we can use Cron:

crontab -e

# this will keep your IP record up to date, running the script every 5 minutes

*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
Router settings

All you need to do with your router is to enable port forwarding and assign an internal static IP for your Pi. Every router is different, so just look up how it's done on yours. In case of this guide, you need to forward the 443 port to the Pi and assign it whatever static IP you want internally. It really doesn't matter.

Now you own a cloud storage

It's a very simple setup. It offers nothing more than just your own WebDAV server. You can do whatever and use it however you like. It seems to be nothing special, but it shows how with a relatively small amount of resources you can get something that:

  • costs much less than what the current market can offer
  • offers a widely supported way to access it with no proprietary bullshit

But the most important part here for me is that you get back a little bit of your digital freedom.