VOOZH about

URL: https://dev.to/vultr/deploying-nextcloud-private-cloud-storage-on-ubuntu-2404-9c3

⇱ Deploying Nextcloud Private Cloud Storage on Ubuntu 24.04 - DEV Community


Nextcloud is an open-source collaboration platform that provides file sync and share, calendars, contacts, video calls, and office collaboration on infrastructure you control. This guide deploys Nextcloud with a MariaDB backend and Redis cache using Docker Compose, with Traefik handling automatic HTTPS. By the end, you'll have Nextcloud serving files and apps securely at your domain.


Set Up the Directory Structure

1. Create the project directory structure:

$mkdir -p ~/nextcloud/{data,mysql,redis,letsencrypt}
$cd ~/nextcloud

2. Create the environment file:

$nano .env
NEXTCLOUD_DOMAIN=nextcloud.example.com
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=STRONG_ADMIN_PASSWORD

MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=STRONG_DB_PASSWORD
MYSQL_ROOT_PASSWORD=STRONG_ROOT_PASSWORD

LETSENCRYPT_EMAIL=admin@example.com

Deploy with Docker Compose

1. Add your user to the Docker group:

$sudo usermod -aG docker $USER
$newgrp docker

2. Create the Docker Compose manifest:

$nano docker-compose.yml
services:
 traefik:
 image: traefik:latest
 container_name: traefik
 restart: unless-stopped
 environment:
 DOCKER_API_VERSION: "1.44"
 command:
 - "--providers.docker=true"
 - "--providers.docker.exposedbydefault=false"
 - "--entrypoints.web.address=:80"
 - "--entrypoints.websecure.address=:443"
 - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
 - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
 - "--certificatesresolvers.le.acme.httpchallenge=true"
 - "--certificatesresolvers.le.acme.httpchallenge.entrypoint=web"
 - "--certificatesresolvers.le.acme.email=${LETSENCRYPT_EMAIL}"
 - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
 ports:
 - "80:80"
 - "443:443"
 volumes:
 - /var/run/docker.sock:/var/run/docker.sock:ro
 - ./letsencrypt:/letsencrypt

 mariadb:
 image: mariadb:10.11
 container_name: nextcloud_db
 restart: unless-stopped
 environment:
 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
 MYSQL_DATABASE: ${MYSQL_DATABASE}
 MYSQL_USER: ${MYSQL_USER}
 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
 volumes:
 - ./mysql:/var/lib/mysql
 healthcheck:
 test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
 interval: 10s
 timeout: 5s
 retries: 3

 redis:
 image: redis:latest
 container_name: nextcloud_redis
 restart: unless-stopped
 volumes:
 - ./redis:/data
 healthcheck:
 test: ["CMD", "redis-cli", "ping"]
 interval: 10s
 timeout: 5s
 retries: 3

 nextcloud:
 image: nextcloud:latest
 container_name: nextcloud
 restart: unless-stopped
 depends_on:
 mariadb:
 condition: service_healthy
 redis:
 condition: service_healthy
 environment:
 NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER}
 NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD}
 NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_DOMAIN}
 MYSQL_HOST: mariadb
 MYSQL_DATABASE: ${MYSQL_DATABASE}
 MYSQL_USER: ${MYSQL_USER}
 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
 REDIS_HOST: redis
 OVERWRITEPROTOCOL: https
 OVERWRITECLIURL: https://${NEXTCLOUD_DOMAIN}
 volumes:
 - ./data:/var/www/html
 labels:
 - "traefik.enable=true"
 - "traefik.http.routers.nextcloud.rule=Host(`${NEXTCLOUD_DOMAIN}`)"
 - "traefik.http.routers.nextcloud.entrypoints=websecure"
 - "traefik.http.routers.nextcloud.tls=true"
 - "traefik.http.routers.nextcloud.tls.certresolver=le"
 - "traefik.http.services.nextcloud.loadbalancer.server.port=80"
 - "traefik.http.middlewares.nc-dav.redirectregex.regex=https://(.*)/.well-known/(card|cal)dav"
 - "traefik.http.middlewares.nc-dav.redirectregex.replacement=https://$$1/remote.php/dav/"
 - "traefik.http.routers.nextcloud.middlewares=nc-dav"

3. Start the services:

$docker compose up -d

4. Verify the services are running:

$docker compose ps

Access Nextcloud

Open https://nextcloud.example.com in a browser and sign in with NEXTCLOUD_ADMIN_USER / NEXTCLOUD_ADMIN_PASSWORD. Nextcloud completes its install on first request — wait a few seconds for the dashboard to load.


Next Steps

Nextcloud is running and served securely over HTTPS. From here you can:

  • Install the desktop and mobile clients for two-way sync across devices
  • Enable apps from the App Store (Talk, Office, Calendar, Mail, Photos)
  • Configure background jobs with cron and set up encrypted external storage

For the full guide with additional tips, visit the original article on Vultr Docs.