How to Self-Host Nextcloud on a VPS
For anyone who wants Dropbox-style file sync without the subscription or the snooping: install Nextcloud on your own VPS with Docker Compose and HTTPS.

Nextcloud gives you file sync, calendars, contacts, photos and document editing on infrastructure you control. This guide installs it with Docker Compose on a fresh Ubuntu VPS, puts it behind HTTPS, and gets your first client syncing. Budget about 30 minutes.
What you need
- A VPS with at least 2 GB RAM (Nextcloud plus a database is comfortable there; more if many users). See the notes in 12 best self-hosted apps to run on a VPS for sizing other services alongside it.
- A domain name with an A record pointing at your server's IP.
- Docker and Docker Compose installed. If you haven't done that yet, follow how to run Docker on a VPS first.
Open the firewall
Nextcloud is served over 80/443. Allow SSH plus web traffic and nothing else:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
If UFW is new to you, the securing your first Linux VPS walkthrough covers the rest of the hardening basics.
The Docker Compose stack
Create a project directory and a compose.yaml. We'll run Nextcloud with a MariaDB database and a Caddy reverse proxy that handles TLS certificates automatically.
mkdir -p ~/nextcloud && cd ~/nextcloud
services:
db:
image: mariadb:11
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
- MARIADB_ROOT_PASSWORD=change-me-root
- MARIADB_DATABASE=nextcloud
- MARIADB_USER=nextcloud
- MARIADB_PASSWORD=change-me-db
app:
image: nextcloud:apache
restart: unless-stopped
depends_on:
- db
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=change-me-db
- NEXTCLOUD_TRUSTED_DOMAINS=cloud.example.com
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
depends_on:
- app
volumes:
db:
nextcloud:
caddy_data:
Now the Caddyfile next to it. Replace the domain with yours:
cloud.example.com {
reverse_proxy app:80
}
Caddy fetches a free Let's Encrypt certificate the first time it starts, so you get HTTPS with no manual steps. If you'd rather use Nginx, see set up Nginx with free SSL using Let's Encrypt.
Start it and finish setup
docker compose up -d
docker compose logs -f app
Wait for the app container to finish initialising, then open https://cloud.example.com. Create the admin account and let the install complete.

First things to do after install
- Install the desktop and mobile clients and sign in — files sync instantly.
- In Settings → Overview, work through any security warnings. The most common fixes are adding a memory cache and setting the maintenance window.
- Add a memory cache. Enter the container and add this line to
config/config.php:'memcache.local' => '\OC\Memcache\APCu',. - Set up server-side encryption only if you actually need it — it complicates recovery.
Backups
Your data lives in two Docker volumes: the database and the nextcloud volume. Back both up on a schedule:
docker compose exec db mysqldump -u nextcloud -p'change-me-db' nextcloud > backup-$(date +%F).sql
Copy that dump plus the data volume to off-server storage. A snapshot or an attached block-storage volume makes this painless.
Get more from your instance
Nextcloud is a platform, not just file storage. Open the app store from the top-right menu and add what you actually need:
- Calendar and Contacts turn it into a full CalDAV/CardDAV server your phone syncs to natively — a real replacement for Google Calendar and Contacts.
- Notes and Tasks give you a private, cross-device to-do and notes system.
- Collabora Online or OnlyOffice add live document editing in the browser. Genuinely useful, but the document server wants extra RAM, so add it only if you have headroom.
- Talk provides private voice and video calls.
Resist installing everything at once — each app adds background jobs. On that note, switch background jobs from AJAX to Cron under *Administration settings → Basic settings* so housekeeping runs reliably, and add a host cron entry:
*/5 * * * * docker compose -f ~/nextcloud/compose.yaml exec -T -u www-data app php cron.php
Updating safely
Upgrades are a one-liner with Docker, but always back up first. Pull the new image, recreate the container and run the upgrade:
cd ~/nextcloud
docker compose pull
docker compose up -d
docker compose exec -u www-data app php occ upgrade
Upgrade one major version at a time — Nextcloud does not support skipping releases. That occ command-line tool inside the container is your maintenance Swiss Army knife: enabling maintenance mode, repairing the database and managing users all live there.
Clients and external storage
The clients are what make Nextcloud a daily driver:
- Desktop client (Windows, macOS, Linux) keeps a folder in sync like Dropbox, with selective sync so you don't pull everything onto a small laptop.
- Mobile apps auto-upload your camera roll and give you offline access to starred files.
- Native sync: point your phone's built-in calendar and contacts at Nextcloud over CalDAV/CardDAV — no extra app required.
Nextcloud can also mount external storage — an S3 bucket, an SFTP server or a second disk — and present it inside your files view. That's handy for attaching bulk block storage without moving your primary data. Configure it under *Administration → External storage*, and each user can optionally add their own external mounts too.
FAQ
How much RAM does Nextcloud need on a VPS?
A single-user or small-family instance runs fine on 2 GB. For a dozen active users add RAM and consider moving the database to its own service; 4 GB is a comfortable target.
Can I use Nextcloud instead of Google Drive?
Yes. It covers file sync and sharing, plus calendars, contacts and a photos app. The trade-off is that you maintain updates and backups yourself.
Is Nextcloud secure to expose to the internet?
It's designed to be public-facing. Keep it updated, force HTTPS, enable two-factor authentication for admins, and put a firewall in front. Pair it with a VPN if you want an extra layer — see how to set up a WireGuard VPN server.
Do I need Docker to run Nextcloud?
No, but Docker Compose is the cleanest install and makes upgrades a one-line command. The manual LAMP install works too if you prefer.
Want a private cloud without babysitting the plumbing? Spin it up on an NVMe Nextcloud VPS with one-click images and full root access, or compare plans on the VPS pricing page.