Skip to main content

Minimal Install

Nextcloud Installation using Docker Compose

This method includes Redis and MariaDB

First lets update your system.

sudo apt-get update && apt-get upgrade -y

Setting up the directories

Now lets setup the Directories

note

You can change the directories to your liking.

sudo mkdir /var/docker && sudo mkdir /var/docker/nextcloud

Lets take ownership of the directory

sudo chown -R 1000:1000 /var/docker

Creating .env files

Now lets make an Environment File with Interpolation file in the new directory.

cd /var/docker/nextcloud

Now lets make the environment file.

nano .env
warning

When editing the configuration below, remove all instances of <> from the values

Paste the Following

Highlighted items will need to be modified
# =============================================================================
# NEXTCLOUD ENHANCED DOCKER-COMPOSE CONFIGURATION
# =============================================================================
# Copy this file to .env and customize the values below
# All values have secure defaults - change passwords for production use!

# =============================================================================
# NEXTCLOUD CONFIGURATION
# =============================================================================
# Nextcloud & MariaDB
# Directory paths for persistent data storage
DATA_LOCATION=./nextcloud
DB_DATA_LOCATION=./mariadb
NEXTCLOUD_TRUSTED_DOMAINS=cloud.<YourDomain>.com
TRUSTED_PROXIES=<IP address of your Reverse Proxy>
OVERWRITEPROTOCOL=https
OVERWRITECLIURL=https://cloud.<YourDomain>.com
REDIS_HOST=redis
REDIS_PORT=6379
# =============================================================================
# PERFORMANCE CONFIGURATION
# =============================================================================
PHP_MEMORY_LIMIT=1024M
PHP_UPLOAD_LIMIT=2048M

# =============================================================================
# NETWORK CONFIGURATION
# =============================================================================
# Main Nextcloud HTTP port
HTTP_PORT=8080

# =============================================================================
# DATABASE CONFIGURATION
# =============================================================================
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=password
MYSQL_PASSWORD=CHANGEME
MYSQL_ROOT_PASSWORD=CHANGEME
MARIADB_AUTO_UPGRADE=true
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_HOST=mariadb
Info

Please Change CHANGEME to a password of your choosing.

danger

Refrain from using Special characters for you MySQL Passwords.
Ex. ‘ ~ ! @ # $ % ^ & * ( ) _ - + = { } [ ] / < > , . ; ? ' : | (space)

Save the new file by pressing CTRL+X

Creating the Compose file

Now lets create the compose file.

nano docker-compose.yaml

Paste this into the file

The highlighted lines are Optional and can be removed completely
name: nextcloud

services:
mariadb:
image: mariadb:10.11
container_name: mariadb
restart: always
command: >
--transaction-isolation=READ-COMMITTED
--log-bin=binlog
--binlog-format=ROW
--log_bin_trust_function_creators=true
--innodb-file-per-table=1
--skip-innodb-read-only-compressed
--innodb-buffer-pool-size=1G
--innodb-log-file-size=256M
--innodb-flush-log-at-trx-commit=1
--innodb-flush-method=O_DIRECT
--max-connections=200
--thread-cache-size=50
--query-cache-type=1
--query-cache-size=256M
--sort-buffer-size=2M
--read-buffer-size=2M
--read-rnd-buffer-size=8M
--myisam-sort-buffer-size=128M
--table-open-cache=2000
--tmp-table-size=256M
--max-heap-table-size=256M
--slow-query-log=1
--slow-query-log-file=/var/log/mysql/slow.log
--long-query-time=2
volumes:
- ${DB_DATA_LOCATION:-db_data}:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_CHARSET=utf8mb4
- MYSQL_COLLATION=utf8mb4_unicode_ci
env_file:
- .env
networks:
- nextcloud
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"

nextcloud:
image: nextcloud:production
container_name: nextcloud
restart: always
ports:
- "${PORT:-8080}:80"
links:
- mariadb
- redis
volumes:
- ${DATA_LOCATION:-nextcloud_data}:/var/www/html
- /etc/localtime:/etc/localtime:ro
environment:
# Enhanced environment variables for better performance
- PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-1024M}
- PHP_UPLOAD_LIMIT=${PHP_UPLOAD_LIMIT:-2048M}
- PHP_MAX_EXECUTION_TIME=3600
- PHP_MAX_INPUT_TIME=3600
- NEXTCLOUD_INIT_HTACCESS=1
- APACHE_DISABLE_REWRITE_IP=1
- APACHE_DOCUMENT_ROOT=/var/www/html
- APACHE_LOG_DIR=/var/log/apache2
env_file:
- .env
depends_on:
mariadb:
condition: service_healthy
redis:
condition: service_healthy
networks:
- nextcloud
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/status.php"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"

redis:
container_name: redis
image: redis:latest
command: >
redis-server
--save 60 1
--loglevel warning
--appendonly yes
--appendfsync everysec
--maxmemory 1gb
--maxmemory-policy allkeys-lru
--tcp-keepalive 300
--timeout 300
volumes: # Optional
- type: tmpfs # Optional
target: /data # Optional
tmpfs: # Optional
size: 1073741824 # 1GB "Optional"
- /etc/localtime:/etc/localtime:ro
expose:
- 6379
networks:
- nextcloud
environment:
- REDIS_REPLICATION_MODE=master
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
restart: always

watchtower:
container_name: watchtower
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock

networks:
nextcloud:
driver: bridge
warning

tmpfs uses memory (RAM), adjust the value as needed or optionally remove the volume section from the redis container

Starting Nextcloud

Now lets start it up.

sudo docker compose up -d
info

the -d flag stands for detatched mode.

After its done pulling the docker images you can open up a web browser.

note

Before proceeding, you will need to configure your reverse proxy. I have an example Nginx config Here.

Connect to nextcloud by typing in your configured domain

You should see this screen.

Nextcloud First Start

warning

If you see this warning


Performance warning

You chose SQLite as database.

SQLite should only be used for minimal and development instances. For production we recommend a different database backend.

If you use clients for file syncing, the use of SQLite is highly discouraged.

You will need to click the drop down and select MySQL/MariaDB and type in the info manually.

  • database account: nextcloud
  • database password: YOUR_PASSWORD_FROM .env
  • database name: nextcloud
  • database host: mariadb:3306

Account Creation

Now create an admin account and click Install

Click Install Recommended Apps

Nextcloud Install Recommended Apps

When its done installing you should see your Dashboard

Nextcloud Dashboard

Checking for errors and warnings

On the top right click the User Icon and go to Administration Settings

Nextcloud Administration Settings

Here you should see Security & Setup Warnings

Nextcloud Warnings

In order to fix the Maintenance Window and the Phone Region warnings, we will have to edit our config.php file.

Modifying the config.php file

Run the following command to open the config.php file with nano.

nano nextcloud/config/config.php
Hint

If you recieved an error Directory nextcloud doesnt exist, then you need to change directories.

Run cd /var/docker/nextcloud then try again.

Now add the following to the bottom of the file.

You may change the highlighted line to your Time Zone Identifier
  'maintenance_window_start' => 1,
'default_phone_region' => 'US',

Nextcloud config.php

Now if you go back to your Administration Settings Page.

It should look something like this.

Nextcloud No Warnings

HINT

In some cases, you may have to delete your browser cache and restart the browser for the Warnings to update.

Creating production use user

Now you can go create a user for yourself.

Go to the user icon on the top right and select Users.

Nextcloud Users

Click on Add User on the left hand side.

Nextcloud Add Users

Now create your User.

Caution

Make sure to set Groups to admin

Nextcloud Add Users1

Congragulations!! you have installed Nextcloud!

Buy me a beer


💬 Discord Community Chat

Join the conversation! Comments here sync with our Discord community.

💬 Recent Comments

Loading comments...
💬Join Discord
Buy me a coffee