Which VPS for Nextcloud?
Nextcloud needs a bit of memory for PHP and its database. Count on the VPS Start (2 GB of RAM, 20 GB SSD) for one or two people who mostly sync documents, and the VPS Plus (4 GB, 40 GB) for a family, photos or a few extra apps. The disk space on our plans goes up to 100 GB: comfortable for documents, tight for a full photo library.
Choose a KVM VPS for Docker, and follow our Docker on an IPv6 VPS guide first: it installs Docker, the NAT64 service and the IPv6 setting this guide relies on.
1. The domain name and IPv4 access
Create an AAAA record, for example cloud.example.com, pointing to the VPS's IPv6 address. Two cases then arise:
- All your devices have IPv6 (recent French home routers and mobile plans): nothing else to do, Caddy will get a Let's Encrypt certificate by itself.
- Some only have IPv4 (hotel Wi-Fi, company network): put the domain behind Cloudflare with the proxy enabled, as in the IPv6 VPS guide, and generate a Cloudflare origin certificate (SSL/TLS tab, "Origin Server").
On Cloudflare's free plan, a request cannot exceed 100 MB. This is not a problem in practice: the web interface and the Nextcloud clients upload large files in small chunks.
2. Prepare the files
mkdir -p /srv/nextcloud/certs && cd /srv/nextcloud
Create a .env file with long, different passwords (openssl rand -base64 24 generates one). The change-me-1 and change-me-2 values below are placeholders: replace them with your own passwords.
DOMAIN=cloud.example.com
MYSQL_ROOT_PASSWORD=change-me-1
MYSQL_PASSWORD=change-me-2
chmod 600 .env
3. The docker-compose.yml file
services:
db:
image: mariadb:11
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db:/var/lib/mysql
networks: [nc]
redis:
image: redis:alpine
restart: unless-stopped
networks: [nc]
app:
image: nextcloud:stable-apache
restart: unless-stopped
depends_on: [db, redis]
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
REDIS_HOST: redis
NEXTCLOUD_TRUSTED_DOMAINS: ${DOMAIN}
OVERWRITEPROTOCOL: https
TRUSTED_PROXIES: 172.16.0.0/12 fd00::/8
volumes:
- nextcloud:/var/www/html
networks: [nc]
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./certs:/certs:ro
- caddy:/data
networks: [nc]
networks:
nc:
enable_ipv6: true
volumes:
db:
nextcloud:
caddy:
The named volumes keep your data when the containers are recreated during updates.
4. The Caddyfile
Create /srv/nextcloud/Caddyfile. Without Cloudflare, Caddy obtains and renews a Let's Encrypt certificate by itself:
cloud.example.com {
reverse_proxy app:80
redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301
}
With Cloudflare, save the origin certificate in certs/origin.pem and its key in certs/origin.key, then add this line just after the opening brace:
tls /certs/origin.pem /certs/origin.key
In Cloudflare, then set SSL/TLS encryption to "Full (strict)".
5. Start up and finish the installation
docker compose up -d
docker compose logs -f app
Open https://cloud.example.com: Nextcloud asks you to create the administrator account. The database is already configured by the variables in the Compose file.
6. Background jobs
Nextcloud needs to run maintenance tasks regularly. Add this line to root's crontab (crontab -e):
*/5 * * * * docker compose -f /srv/nextcloud/docker-compose.yml exec -T -u www-data app php -f /var/www/html/cron.php
In Nextcloud, open Administration settings, Basic settings, and choose "Cron". Then install the Nextcloud apps on your computers and phone, and connect them to your address.
Updating
cd /srv/nextcloud
docker compose pull
docker compose up -d
Nextcloud cannot skip a major version: the stable image follows versions in order, so update regularly rather than once a year.