Nextcloud Setup Guide - ajgillis04/GillisDockerDepot GitHub Wiki

Nextcloud Containerized Setup Guide

Introduction

This guide provides steps to set up a Nextcloud instance using a regular containerized setup. It is ideal if you require full control over the deployment or if you’ve migrated from Nextcloud AIO.

Recommended Pre-Setup

Before setting up Nextcloud, consider deploying the following containers first to simplify integration and avoid jumping between configuration steps:

  • MariaDB (For selfhosting databases)

Prerequisites

  • Docker and docker-compose installed
  • NAS storage or a local directory for external storage
  • Environment variables for modular configuration

Configuration Steps

Step 1: Prepare the Docker Environment

  1. Create / Update the .env file to manage configurations:

    NEXTCLOUD_HOMES=/path/to/homes  # Avoid using symlinks; Nextcloud does not handle them well
    NEXTCLOUD_EXSTORAGE=/share
    

    Create a blank database in MariaDB for nextcloud to use

    docker exec -it mariadb.${HOST_NAME} /usr/bin/mariadb -u root -p
    CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    CREATE USER 'nextclouduser'@'%' IDENTIFIED BY 'yourpassword';
    GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'%';
    FLUSH PRIVILEGES;
    EXIT;
    

    Run this command to test if the DB is setup correctly

    docker exec -it mariadb.${HOST_NAME} mysql -u nextclouduser -p --password={your password} -e "SHOW DATABASES;"
    

Step 2: First-Time Setup

  1. Open your browser and navigate to http://<your-server-ip>:8080.
  2. Select Storage & Database
  3. Enter an New admin account name and specify the database connection:
    • Database account: contents of secrets/nextcloud_mysql_user
    • Database password: contents secrets/nextcloud_mysql_password
    • Database Name: nextcloud
    • Database Host: mariadb.${HOST_NAME}

NextCloud Intial1 NextCloud Intial

Step 3: Install Apps (Optional)

  1. Nextcloud asks you which apps if any you wish to install. I choose
    • Calendar
    • Contacts
    • Mail
    • Nextcloud Office
    • Notes

Step 4: Configure Basic Settings

  1. Set Up External Storage:
    • Enable the External Storage Support app under Settings > Apps. Enable, enter your password if required
    • Go to Settings > Administration > External storages and add your storage volumes (e.g., /homes).

NextCloud ExternalStorage

  1. Modify config.php:
    • Add or edit the following
      sudo docker run -it --rm --volume /path/to/GillisDockerDepot/appdata/nextcloud/var/www/html:/var/www/html:rw alpine sh -c "apk add --no-cache nano && nano /var/www/html/config/config.php"
      Add or adjust:
      'trusted_domains' => [
        'localhost',
        'your-domain.com',
        'your host ip example 192.168.1.100',
      ],
      'default_phone_region' => 'CA',
      'trusted_proxies' =>
       array (
         0 => '172.30.0.0/24', # container IP range, in case IP changes
         1 => '192.168.2.0/24',# domain IP range, in case IP changes
         2 => '127.0.0.1',
         3 => '::1',
      'memcache.local' => '\\OC\\Memcache\\APCu',
      'overwrite.cli.url' => 'https://nextcloud.gillisonline.com',
      'overwritehost' => 'nextcloud.gillisonline.com',
      'overwriteprotocol' => 'https',
      'overwritewebroot' => '/',
      'maintenance_window_start' => '03:00',
      'memcache.locking' => '\\OC\\Memcache\\APCu',
    • Save and restart the container:
      docker restart nextcloud.$<HOST_NAME>

Step 5: Other Settings

  1. Set up a whitelist for your IP. Top right, select the A, administrative settings, security, brute-force IP whitelist, Add a new whitelist. Add your ISP assigned IP. I use /24 in case my ISP changes my IP.

    NextCloud Config2 NextCloud Config3
    Note: This helps prevent locking yourself out in case of misconfiguration.

  2. Set password policy as per your requirements.

    NextCloud Config4

  3. Set up the email server. From the administration, go to basic settings, email server, and enter the settings.

    NextCloud Config6
    Note: This ensures users receive messages when their accounts are created.

  4. Set up users and groups. Click on the A at the top right, then accounts.

    NextCloud Config5

    Note: I use a script to create my accounts, e.g.,

    export OC_PASS=whateverpassword
    /var/www/html/occ user:add --password-from-env --display-name="Test User" --group="users" [email protected]
    
  5. Setup external storage, Click on the A top right, apps, your apps, scroll to bottom and enable External storage

    • Go to External storages under the Administration section and set your external storage.

    NextCloud Config7 I create a Documents folder for each user on the NAS that points back to their home drive and a few others

    NextCloud Config8
    Note: For NASShares I also turn on enable sharing allowing me to create shares for others.

  6. Last step I do is add my domain, local IP, and phone code to the config.php

    sudo docker run -it --rm --volume nextcloud:/var/www/html:rw alpine sh -c "apk add --no-cache nano && nano /var/www/html/config/config.php" 

    NextCloud Config9 NextCloud Config10

Setting Up Phone for Auto Backups

  1. Open the Nextcloud app and enter the Server address

NextCloud Phone4
*Note: You will be redirected to your browser to enter your Nextcloud credentials.

  1. Connect to your account.

NextCloud Phone5

  1. Grant Access

    NextCloud Phone6

  2. Navigate to Documents.

  3. Tap + and select Create new Folder.

  4. Name the new folder Photos.

    NextCloud Phone1

  5. Go back twice.

  6. Open the Burger menu.

  7. Go to Settings.

  8. Select Auto upload.

  9. Tap (ellipsis) and configure the folder you want to upload.

  10. Enable Auto upload.

  11. Change the Remote folder to the newly created Photos folder.

    NextCloud Phone2
    NextCloud Phone3

Step 5: Maintenance and Logs

  1. To clear logs:

    docker exec -it nextcloud.GillisNAS bash -c "echo '' > /var/www/html/data/nextcloud.log"
  2. Monitor resource usage:

    docker stats

Step 6: Setting Up Auto Backups

Follow the steps from Setting Up Phone for Auto Backups in the original guide.


⚠️ **GitHub.com Fallback** ⚠️