Skip to main content

Command Palette

Search for a command to run...

Deploying Nextcloud Private Cloud Storage on Ubuntu 24.04

Step-by-step guide to deploy Nextcloud with MariaDB, Redis, Docker Compose, and Traefik on Ubuntu 24.04, with persistent storage and automatic HTTPS for a private cloud platform.

Updated
3 min read
Deploying Nextcloud Private Cloud Storage on Ubuntu 24.04
S
A Developer Advocate with a focus on improving the developer experience through clear communication, technical enablement, and community engagement.
A
DevOps Engineer with experience in Kubernetes, automation, cloud infrastructure, and observability. I work in Developer Relations, contribute to technical documentation, and collaborate on engineering-focused projects.

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, following private cloud storage deployment practices documented in Vultr Docs.


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.

The Self-Hosted Stack

Part 37 of 50

The Self-Hosted Stack is a developer-focused series exploring open-source tools you can deploy, run, and manage on your own infrastructure. From AI platforms and databases to developer tools, observability stacks, and authentication systems, each guide walks through deploying production-ready open-source software on Vultr cloud infrastructure.

Up next

Deploying ownCloud File Sharing Platform on Ubuntu 24.04

Step-by-step guide to deploy ownCloud with MariaDB, Redis, Docker Compose, and Traefik on Ubuntu 24.04, with persistent storage and automatic HTTPS for a self-hosted file sharing platform.

More from this blog

V

Vultr

71 posts

Vultr is a global cloud infrastructure provider trusted by developers and businesses in 185+ countries. We publishe hands-on guides spanning Linux administration, server configuration, DevOps, networking, open source stacks, AI code agents, and Vultr product walkthroughs, all tested against real cloud environments and built for engineers who ship.