How to Self-Host Nextcloud on a VPS (with Dokploy)
If you want to self host Nextcloud on a VPS, here's the short answer: rent a small Linux server, install Dokploy on it, and deploy Nextcloud from Dokploy's template. You get your own Dropbox-style file sync, on your own domain with HTTPS, with a database and a cache already wired in. The only bill is the server.
I'll go step by step, for someone who has never self-hosted anything. There's one thing about the order of the steps that trips people up, and I'll point it out when we get there. Then I'll show the easier way, where I asked Claude to check what the template would create before I created anything.
What you need
- A VPS. Dokploy asks for at least 2 GB of RAM and 30 GB of disk. That runs Dokploy plus a small Nextcloud. Your files live on this disk too, so pick the disk size for how much you plan to store, not for Nextcloud itself. Hetzner, DigitalOcean, Hostinger and others all work. Choose Ubuntu or Debian.
- A domain you can add a DNS record to, like
cloud.yourdomain.com. Nextcloud's apps and desktop clients want HTTPS, and HTTPS needs a domain.
No license needed. Nextcloud's server is open source and free to run.
Step 1: Install Dokploy
SSH into your server and run Dokploy's install script:
curl -sSL https://dokploy.com/install.sh | sh
Ports 80, 443 and 3000 must be free first, or the install fails. When it finishes, open http://your-server-ip:3000 and create your admin account.
Step 2: Create the Nextcloud template (don't deploy yet)
Dokploy has a gallery of one-click templates. My Dokploy lists 701 of them, and one is Nextcloud.
- Create a project (call it anything, like "files").
- Inside it, click Create Service, choose Template, search for Nextcloud and create it.
Here's what the template sets up. It's a Docker Compose service with four containers:
| Container | What it does |
|---|---|
nextcloud |
Nextcloud itself, the official nextcloud image, pinned to 33.0.6 |
nextcloud_cron |
The same image running Nextcloud's background jobs every few minutes |
nextcloud_db |
MariaDB 10.11, the database |
nextcloud_redis |
Redis, for caching and file locking |
Dokploy also generates the two database passwords for you and gives the service a free generated domain. The template's id is nextcloud-aio, but it isn't Nextcloud AIO (Nextcloud's own all-in-one installer). It's the plain official image plus MariaDB and Redis, which is easier to understand and back up.
Step 3: Add your domain with HTTPS before the first visit
This is the step that trips people up. When you open Nextcloud for the first time and create your admin account, Nextcloud saves the address you used as its only trusted domain. If you do that on the generated test domain and switch to your own domain later, you get the "Access through untrusted domain" page instead of your files.
So set your real domain first:
- At your DNS provider, add an A record for
cloud.yourdomain.compointing to your server's IP. If you use Cloudflare, set it to DNS only (grey cloud) so Let's Encrypt can reach your server. - In Dokploy, open the service's Domains tab and edit the domain: host
cloud.yourdomain.com, servicenextcloud, port80, turn on HTTPS, and pick Let's Encrypt.
Port 80 is right even though you want HTTPS. Traefik (the proxy Dokploy runs for you) handles the certificate and talks to Nextcloud over port 80 inside the server.
Step 4: Deploy and create your admin account
Click Deploy. The first start takes a minute or two while Nextcloud sets up its database. Then open https://cloud.yourdomain.com, create your admin account, and you're in.
For Docker Compose services, Dokploy reads domains from Docker labels, so if you change the domain later you have to redeploy (and add the new domain to Nextcloud's trusted domains, see the FAQ).
Step 5: Run the template's setup script
Open the Environment tab and you'll see settings like OVERWRITEPROTOCOL=https, TRUSTED_PROXIES and REDIS_HOST. Here's the catch: the Compose file only passes the four MYSQL_ settings into the Nextcloud container. The rest sit in the Environment tab but never reach Nextcloud on their own.
The template solves this with a script it mounts into the container, fix-nextcloud.sh. Its own instructions say to run it once, after you've created your admin account. Open a terminal on the nextcloud container from the service in Dokploy and run:
su -s /bin/sh www-data -c "/bin/sh /usr/local/bin/fix-nextcloud.sh"
It does five things: trusts Traefik as a proxy, tells Nextcloud it's served over HTTPS, sets a maintenance window, adds missing database indexes, and switches caching and file locking to Redis. It only runs once (it leaves a marker file behind).
One detail: the script sets the default phone region to DE (Germany), whatever the Environment tab says. If you're not in Germany, change it afterwards in the same terminal, for example for Kenya:
su -s /bin/sh www-data -c "php occ config:system:set default_phone_region --value=KE"
Then check Administration settings > Overview in Nextcloud. That page lists any warnings left.
Step 6: Back it up
Your files and Nextcloud's config live in the nextcloud_data volume, and your users, shares and file index live in MariaDB's nextcloud_db_data volume. You need both. Dokploy can back up a Docker volume on a schedule to any S3-compatible storage. Set up a destination once, then schedule backups for both volumes. Do it on day one, not after something breaks.
No template? The Docker Compose route
If you want to start from your own file, choose Create Service, then Compose, and paste a Compose file. Here's one that passes the proxy, HTTPS and Redis settings into the container directly, so those work without a script:
services:
nextcloud:
image: nextcloud:33.0.6
restart: always
expose:
- 80
volumes:
- nextcloud_data:/var/www/html
environment:
- MYSQL_HOST=nextcloud_db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- REDIS_HOST=nextcloud_redis
- OVERWRITEPROTOCOL=https
- TRUSTED_PROXIES=10.0.0.0/8 172.16.0.0/12
depends_on:
- nextcloud_db
- nextcloud_redis
nextcloud_cron:
image: nextcloud:33.0.6
restart: always
volumes:
- nextcloud_data:/var/www/html
entrypoint: /cron.sh
depends_on:
- nextcloud_db
nextcloud_db:
image: mariadb:10.11
restart: always
volumes:
- nextcloud_db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
nextcloud_redis:
image: redis:alpine
restart: always
volumes:
nextcloud_data:
nextcloud_db_data:
Put MYSQL_PASSWORD and MYSQL_ROOT_PASSWORD (two long random strings) in the Environment tab, add your domain on port 80 like in Step 3, and deploy. Then open your domain (not the generated one) to create the admin account, for the same trusted domain reason. There's no ports: line on purpose. Traefik sends traffic from your domain to the container, so nothing is published to the internet directly, including the database.
The easier way: just ask Claude
Everything above is clicking through Dokploy, and Step 5 had me reading a shell script to find out what it did. You can skip learning Dokploy by connecting it to Claude (or any AI that speaks MCP) through Zeqqat. You add your Dokploy URL and an API key to Zeqqat once, then paste Zeqqat's MCP URL into Claude as a connector. After that you say what you want.
Here's what I asked:
Which Nextcloud templates does my Dokploy have? Check what the template would create, without creating anything.
Here's what happened, call by call:
- Claude searched Zeqqat for "template" and found Dokploy's template tools: list templates, preview a template, deploy a template.
- It listed the templates: 701 of them, one Nextcloud (id
nextcloud-aio). That's where the count in Step 2 came from. - It packed the Nextcloud template into Dokploy's preview, which is read only. Dokploy worked out what it would create without saving anything:
domains: nextcloud, port 80, <generated>.sslip.io
envs:
MYSQL_PASSWORD={{zq_secret_7y2p5ljunnsbuyj6}}
MYSQL_ROOT_PASSWORD={{zq_secret_bmr72mp2h6amv3sh}}
DEFAULT_PHONE_REGION=DE
NEXTCLOUD_DOMAIN=<generated>.sslip.io
OVERWRITEPROTOCOL=https
TRUSTED_PROXIES=10.0.0.0/8 172.16.0.0/12
REDIS_HOST=nextcloud_redis
mounts: fix-nextcloud.sh
The two database passwords were generated by Dokploy and never reached Claude: Zeqqat swapped them for {{zq_secret_...}} handles before the answer came back. Claude can still pass a handle back to Dokploy when it deploys, without ever seeing the value.
Reading the preview next to the Compose file is how the two catches in this post came up. The generated domain is plain HTTP while the environment says OVERWRITEPROTOCOL=https, so the domain has to change before the first visit (Step 3). And only the MYSQL_ settings are passed into the Nextcloud container, so the other settings wait for the script (Step 5). Both are things you'd otherwise find out after the fact.
I stopped there. Deploying is one more call, and my Zeqqat connection allows it because it creates something new. Delete is switched off on that connection, so Claude can set things up but can't remove anything. Every call carried the same one-line reason, so in Zeqqat's activity log the whole thing shows up as one request I can read back.
What I took from it
Self-hosting Nextcloud on a VPS is a template, a domain set before the first visit, one script, and two volumes to back up. That gets you your own file sync with a real database and Redis behind it. And if you'd rather not learn where all of that lives in Dokploy, you can ask your AI to check it for you.
Zeqqat is a free and open source MCP gateway for Dokploy. Self-host it or use zeqqat.com. The code is on GitHub.
FAQ
Why does Nextcloud say "Access through untrusted domain"?
Nextcloud only answers on the domains in its trusted_domains list, and the first one is the address you used when you created the admin account. If you set up on one address and moved to another, add the new one from a terminal on the Nextcloud container: su -s /bin/sh www-data -c "php occ config:system:set trusted_domains 1 --value=cloud.yourdomain.com".
Is self-hosted Nextcloud free?
Yes. Nextcloud's server is open source and free to run on your own VPS. You pay for the server and your domain. Nextcloud sells an enterprise subscription for support, but you don't need it to use it.
Is Dokploy's Nextcloud template the same as Nextcloud AIO?
No, even though its id is nextcloud-aio. Nextcloud AIO is Nextcloud's own installer, which starts and manages its own containers. Dokploy's template is the official nextcloud Docker image with MariaDB, Redis and a cron container, defined in one Compose file you can read and edit.