Skip to content

Deploying a Nextcloud App

Introduction

Nextcloud is an open-source content collaboration platform for file sync, sharing, calendars, and more. Deploying Nextcloud with a Dockerfile on Klutch.sh delivers reproducible builds, managed secrets, and persistent storage for user data—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production tips.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your Nextcloud Dockerfile (GitHub is the only supported git source)
  • A database (MariaDB/MySQL recommended; deploy as a Klutch.sh TCP app on port 8000 and connect on 3306)
  • Domain and TLS for secure access

For onboarding, see the Quick Start.


Architecture and ports

  • Nextcloud runs on PHP/Apache; set the internal container port to 8080 and choose HTTP traffic.
  • Database runs separately on TCP; connect on 3306.
  • Persistent storage is required for user data, config, and apps.

Repository layout

nextcloud/
├── Dockerfile # Must be at repo root for auto-detection
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
docker build -t nextcloud-local .
docker run -p 8080:8080 \
-e NEXTCLOUD_ADMIN_USER=admin \
-e NEXTCLOUD_ADMIN_PASSWORD=changeme \
nextcloud-local

Dockerfile for Nextcloud (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM nextcloud:29-apache
ENV APACHE_HTTP_PORT_NUMBER=8080
# Align Apache to port 8080
RUN sed -i 's/80/${APACHE_HTTP_PORT_NUMBER}/g' /etc/apache2/ports.conf /etc/apache2/sites-available/000-default.conf
EXPOSE 8080
CMD ["apache2-foreground"]

Notes:

  • Pin the image tag (e.g., 29-apache) for stability; update intentionally.
  • Add PHP extensions if your apps need them by extending the base image.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • APACHE_HTTP_PORT_NUMBER=8080
  • NEXTCLOUD_ADMIN_USER=<admin-user>
  • NEXTCLOUD_ADMIN_PASSWORD=<strong-password>
  • NEXTCLOUD_TRUSTED_DOMAINS=example-app.klutch.sh
  • Database: MYSQL_HOST=<db-host>, MYSQL_DATABASE=<db-name>, MYSQL_USER=<db-user>, MYSQL_PASSWORD=<db-password>
  • Optional SMTP: SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_NAME, SMTP_PASSWORD

If you deploy without the Dockerfile and need Nixpacks overrides (PHP):

  • NIXPACKS_PHP_VERSION=8.2
  • NIXPACKS_START_CMD=apache2-foreground

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /var/www/html — apps, config, and core files.
  • /var/www/html/data — user data and uploads.

Ensure these directories are writable.


Deploy Nextcloud on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 8080.
  4. Add the environment variables above, including database credentials, admin credentials, and trusted domains.
  5. Attach persistent volumes for /var/www/html and /var/www/html/data, sizing them for your app data and user files.
  6. Deploy. Complete the web installer at https://example-app.klutch.sh and connect to your database.

Sample API usage

List capabilities via WebDAV (example using curl):

Terminal window
curl -u "<admin-user>:<password>" \
-X PROPFIND "https://example-app.klutch.sh/remote.php/dav/files/<admin-user>/" \
-H "Depth: 1"

Health checks and production tips

  • Add an HTTP probe to /status.php for readiness.
  • Enforce HTTPS at the edge; forward internally to port 8080.
  • Keep database and admin credentials in Klutch.sh secrets; rotate them regularly.
  • Monitor volume usage on /var/www/html/data; resize before it fills.
  • Pin image versions and test upgrades in staging; back up data and DB before updates.

Nextcloud on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 8080 configured, and your database connected, you can deliver secure file collaboration without extra YAML or workflow overhead.