How to Self Host Nextcloud on Raspberry Pi
Self host Nextcloud on a Raspberry Pi with hardware that keeps up, a Docker Compose stack, durable storage, and remote access without a static IP.
If you’ve been looking into how to self host Nextcloud on Raspberry Pi, the good news is that it works well for small setups — 1 to 4 users doing file sync, calendar, and contacts. The bad news is that the Pi hits real limits fast, and most guides skip the parts that bite you at month nine. This one doesn’t.
Who this is for (and who should skip it)
This guide is for someone comfortable with SSH and a docker-compose.yml file who wants private cloud storage on hardware they own. You don’t need to have run Nextcloud before.
Skip this if:
- You want zero-maintenance storage — Proton Drive or iCloud are fine, and saying “ditch the cloud” isn’t a thesis here
- You have more than five concurrent users — a Pi genuinely can’t keep up
- You need Nextcloud Office (Collabora/OnlyOffice) or video transcoding — those workloads need an x86 box with more RAM and faster single-thread performance
For file sync, photo backup, shared calendars, and contacts, the Pi is a legitimate choice. If you have not committed to the Pi yet, the Raspberry Pi versus mini PC comparison covers where an N100 box takes over, which is roughly the point where Collabora or transcoding enters the picture. To check whether Nextcloud plus everything else you want will fit the board you own, run the combination through our self-hosted app picker and resource budget estimator before you buy anything.
Hardware that actually works
Raspberry Pi 4 (4GB) is the floor worth recommending. The 2GB model technically runs Nextcloud but you’ll fight swap constantly whenever background jobs run alongside PHP-FPM and MariaDB. Raspberry Pi 5 (8GB) is the comfortable choice — faster I/O, NVMe HAT support, and enough headroom that Redis, the database, and the app don’t constantly compete for memory.
Do not run Nextcloud off a microSD card. The constant database writes wear SD cards out faster than you expect, and the I/O ceiling is low enough that syncing a folder of RAW photos feels painful. Boot from a USB 3.0 SSD on the Pi 4, or use the official Pi 5 NVMe HAT with an M.2 drive.
Practical shopping list:
- Raspberry Pi 5 (8GB) or Pi 4 (4GB)
- Official Raspberry Pi power supply (undersized power causes random crashes, not obvious performance degradation)
- USB 3.0 SSD or Pi 5 + NVMe HAT
- Wired Ethernet — Wi-Fi adds sync jitter that shows up as client errors
The stack
Docker Compose is the cleanest deployment path on a Pi. It keeps Nextcloud, its database, and its cache isolated from the OS and easy to update. The broader case for building a home server stack on Docker Compose covers how quickly a compose file grows once adding a service costs one paste.
Nextcloud 35’s official system requirements specify PHP 8.3/8.4/8.5 and support MariaDB 10.11 through 12.3 (11.8 recommended) or PostgreSQL 14 through 18. The compose file below uses MariaDB 11.8 and Redis, which is a practical combination for Pi-class hardware.
services:
db:
image: mariadb:11.8
restart: unless-stopped
volumes:
- db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
redis:
image: redis:alpine
restart: unless-stopped
nextcloud:
image: nextcloud:stable-fpm-alpine
restart: unless-stopped
depends_on:
- db
- redis
volumes:
- nextcloud:/var/www/html
- /mnt/data:/var/www/html/data
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
REDIS_HOST: redis
NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_TRUSTED_DOMAINS}
NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER}
NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD}
cron:
image: nextcloud:stable-fpm-alpine
restart: unless-stopped
depends_on:
- nextcloud
volumes:
- nextcloud:/var/www/html
- /mnt/data:/var/www/html/data
entrypoint: /cron.sh
proxy:
image: nginx:alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/etc/nginx/certs:ro
- nextcloud:/var/www/html:ro
volumes:
db:
nextcloud:
Store your secrets in a .env file in the same directory — Docker Compose reads it automatically. The /mnt/data bind mount is where files actually land; point it at your external SSD or NVMe, not at a directory on your SD card or OS partition.
The cron service runs Nextcloud’s background maintenance jobs. Without it, tasks pile up and the admin dashboard fills with warnings about overdue jobs. This is one of those things most guides mention in passing and then don’t include in the compose file.
The stable-fpm-alpine image targets 64-bit ARM, which is correct for Pi 4 and Pi 5 running 64-bit Raspberry Pi OS. If you’re on a 32-bit OS for some reason, you’ll need a different image tag — but run 64-bit. The official requirements state 64-bit CPU, OS, and PHP are strongly recommended.
Storage and backups
Mount the data directory on the external drive, not on the OS partition. The root filesystem wearing out shouldn’t wipe your files. Structure it cleanly: OS on one partition, /mnt/data for Nextcloud files on another.
Backups are the part everyone defers. A minimal working approach: rclone to a Backblaze B2 bucket running nightly via cron. B2’s free tier covers 10GB; beyond that it’s $0.006/GB/month. For the database, mysqldump nextcloud piped to your backup destination before the file sync keeps the two consistent.
Restore drill matters more than the backup itself. Schedule one. Point a fresh Pi at your backup and verify you can get files back before you need to. The 3-2-1 backup strategy for a self-hosted stack goes further into application-consistent database dumps and encrypted off-site copies.
If you use Nextcloud AIO (All-in-One) instead of this compose stack, it ships with BorgBackup integration that handles database and files together in one snapshot — worth considering if you’d rather not wire the two up manually.
One caveat specific to photos: Nextcloud’s mobile client will auto-upload your camera roll to this Pi, and the Memories app puts a timeline over it, but a Pi is not the right host for a full Google Photos replacement with server-side face recognition. If photos are the reason you are building this, read self-hosted Google Photos alternatives first — the dedicated photo servers want considerably more RAM than a Pi has spare once Nextcloud is running. Immich versus Google Photos sets out what the dedicated route gains and what it gives up, and if you already have years of library to bring across, the Google Takeout to Immich migration guide covers the sidecar-metadata trap that otherwise strips your dates and albums.
Networking
Three paths to remote access, in order of operational simplicity:
Tailscale is the lowest-friction option for solo or family use. Install it on the Pi and your devices, and Nextcloud becomes accessible over an encrypted mesh without port forwarding or public IP exposure. The Nextcloud desktop and mobile clients work through Tailscale without configuration changes. MagicDNS gives you a stable hostname even if your Pi’s local IP changes.
Cloudflare Tunnel exposes Nextcloud publicly via a cloudflared daemon running on the Pi. You get automatic TLS and a public HTTPS URL without opening router ports. Useful when you need to share files with people who aren’t on your Tailnet. The Nextcloud community forum has a detailed guide covering Cloudflare Zero Trust integration including the nginx config and SSL setup.
Raw port forward (ports 80 and 443 to the Pi) with Let’s Encrypt via certbot is the traditional approach. It works, but it exposes your Pi’s IP directly and requires managing cert renewal. Worth it only if you already have a domain and want full control of the TLS chain.
For most setups: Tailscale if it’s just you and your household, Cloudflare Tunnel if you need external sharing.
Operations
Updates: docker compose pull && docker compose up -d pulls new images and restarts affected services. Nextcloud major version upgrades must go one version at a time — the updater refuses to skip, and so does the Docker image. If you’re on 29 and want 31, go 29 → 30 → 31 with a working backup before each step.
Logs: docker compose logs -f nextcloud for application output. Most problems surface first in the Nextcloud admin panel’s “Overview” tab — check there before digging into logs.
Memory pressure: Redis caching is not optional on Pi hardware. Without it, every PHP request hits MariaDB for session data. With it, repeat page loads are noticeably faster and background job runs don’t cause noticeable slowdowns for active users.
Any publicly-accessible Nextcloud instance should have fail2ban protecting the login endpoint and Nextcloud’s security hardening checklist applied. Enabling the AI assistant apps or external API integrations widens that attack surface further, so leave them off until you have a reason to turn them on.
Sources
Related
20 Self-Hosted Apps to Replace Google Services
Explore 20 self-hosted alternatives to Google Drive, Photos, Gmail, Calendar, Docs, Analytics, and Search, with setup difficulty and hardware notes.
Best Self-Hosted Password Manager in 2026
Vaultwarden, official Bitwarden, Passbolt CE and KeePassXC compared on security, backup needs, and who should skip running a server entirely.
Immich vs Google Photos: What You Gain and Lose
Immich compared to Google Photos on auto-backup, search, sharing, and running cost, with the documented hardware it needs and the risks you inherit.