# NextCloud

How to run NextCloud

# How To run NextCloud

### Overview

I run NExtcloud using a docker. There are 2 options - either manually set it up or do the all-in-one. The all-in-one is new and looks promising, but I saw some performance downgrades.

### NextCloud Individual Services

This is my docker-compose running each of the services independent. It will create a "stack" in Portainer. This was pulled from Their GitHub Repo ([https://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/mariadb/fpm/docker-compose.yml](https://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/mariadb/fpm/docker-compose.yml)).

Since I was running this on windows, I had issues with the CRON service, so I would uncomment that and run it. You can see that there are 2 document servers, one is commented out. I keep going back and forth to find out which one is best. So far I've settled on ONLYOFFICE. there is a werid thing where one of the config files doesn't work right. So there are some commands I have here to copy files from one location to another to get it working - You can most likely skip that for a new setup since it was a hacky fix.

I also did not enable elastic search since it require a lot of resources and some plugins in my existing next cloud was fine.

```yaml
version: '3'
# Note after running I ran 'chmod 755 /var/www/' in the app and web containers. 
#This was before I discovered the redis auth error, which is fixed using requirepass in redis and app container in this compose file. Try not chmodding next time.

services:
  db:
    container_name: nextcloud-db
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --skip-innodb-read-only-compressed
    restart: always
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=passw0rd
      - TZ=America/New_York
    env_file:
      - db.env

  redis:
    container_name: nextcloud-redis
    image: redis:alpine
    command: redis-server --requirepass modi3885
    restart: always
    #user: "1000:1000"

  # collab:
  #   image: collabora/code
  #   container_name: nextcloud-collab
  #   restart: always
  #   cap_add:
  #     - MKNOD
  #   ports:
  #     - 9980:9980
  #   environment:
  #     - username=admin
  #     - password=modi3885
  #     - VIRTUAL_PORT=9980
  #     - domain=.*
  #     - extra_params=--o:ssl.enable=false --o:ssl.termination=true --o:net.post_allow.host[0]=.+ --o:storage.wopi.host[0]=.+'
  #     - TZ=America/New_York
    #location of loolwsd.xml which is main config. these are commands to copy it to host and back:
    # docker cp nextcloud-collab:/etc/loolwsd/loolwsd.xml collabora/loolwsd/loolwsd-Latest_from_container.xml
    # docker cp ./collabora/loolwsd/loolwsd.xml nextcloud-collab:/etc/loolwsd/loolwsd.xml
 
  onlyoffice-document-server:
    container_name: nextcloud-onlyoffice
    image: onlyoffice/documentserver:latest
    stdin_open: true
    tty: true
    restart: always
    ports:
      - 9943:443
      - 9988:80
    volumes:
      - ./onlyoffice/document_data:/var/www/onlyoffice/Data
      - ./onlyoffice/document_log:/var/log/onlyoffice
    #  - ./onlyoffice/nginx/includes:/etc/nginx/includes
    #location of loolwsd.xml which is main config. these are commands to copy it to host and back:
    # docker cp nextcloud-onlyoffice:/etc/onlyoffice/documentserver/nginx/includes/http-common.conf ./onlyoffice/nginx/includes/http-common_Latest_from_container.conf
    # docker cp ./onlyoffice/nginx/includes/http-common.conf nextcloud-onlyoffice:/etc/onlyoffice/documentserver/nginx/includes/http-common.conf

  # elasticsearch:
  #     container_name: nextcloud-elasticsearch
  #     build: ./elastic-docker
  #     restart: always
  #     environment:
  #       - discovery.type=single-node
  #       - http.host=0.0.0.0
  #       - transport.host=0.0.0.0
  #       - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
  #     volumes:
  #       - ./elastic/data:/usr/share/elasticsearch/data
  #       - ./elastic-docker/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  #     ports:
  #       - 9200:9200

  app:
    container_name: nextcloud-app
    image: nextcloud:fpm-alpine
    restart: always
    #user: "1000:1000"
    volumes:
      - nextcloud:/var/www/html
      - ./app/config:/var/www/html/config
      #- ./app/custom_apps:/var/www/html/custom_apps
      - ./app/data:/var/www/html/data
      - ./app/themes:/var/www/html/themes
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - REDIS_HOST_PASSWORD=modi3885
      - TZ=America/New_York
    env_file:
      - db.env
    depends_on:
      - db
      - redis
#      - elasticsearch
      
  web:
    container_name: nextcloud-web
    build: ./web
    restart: always
    ports:
      - 8888:80
    volumes:
      - nextcloud:/var/www/html:ro
      - ./web/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - app
    labels:
      - "com.centurylinklabs.watchtower.enable=false"

  # moving to tasks since there are issues with the container.
  # cron:
  #   container_name: nextcloud-cron
  #   image: nextcloud:fpm-alpine
  #   restart: always
  #   #user: "1000:1000"
  #   volumes:
  #     - nextcloud:/var/www/html
  #   entrypoint: /cron.sh
  #   depends_on:
  #     - db
  #     - redis
  #   network_mode: host
volumes:
  nextcloud:
  db:
```

### NextCloud AIO

Here is the AIO (All-In-One) Version. It works but as I said doesn't have great performance when I tried it. But I didn't really give it a fair shot. It will create a master container then spawn others off of it. Note that you'll have to use the ARM64 version for a raspberry pi. I'm running on a windows docker.

Link to project: [https://github.com/nextcloud/all-in-one](https://github.com/nextcloud/all-in-one)

This is what they suggest

```yaml
version: "3.8"

volumes:
  nextcloud_aio_mastercontainer:
    name: nextcloud_aio_mastercontainer # This line is not allowed to be changed

services:
  nextcloud:
    image: nextcloud/all-in-one:latest # Must be changed to 'nextcloud/all-in-one:latest-arm64' when used with an arm64 CPU
    restart: always
    container_name: nextcloud-aio-mastercontainer # This line is not allowed to be changed
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config # This line is not allowed to be changed
      - /var/run/docker.sock:/var/run/docker.sock:ro # May be changed on macOS, Windows or docker rootless. See the applicable documentation. If adjusting, don't forget to also set 'DOCKER_SOCKET_PATH'!
    ports:
      - 80:80 # Can be removed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      - 8080:8080
      - 8443:8443 # Can be removed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
    # environment: # Is needed when using any of the options below
      # - APACHE_PORT=11000 # Is needed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # - APACHE_IP_BINDING=127.0.0.1 # Should be set when running behind a reverse proxy that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # - COLLABORA_SECCOMP_DISABLED=false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
      # - DOCKER_SOCKET_PATH=/var/run/docker.sock # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail.
      # - DISABLE_BACKUP_SECTION=false # Setting this to true allows to hide the backup section in the AIO interface.
      # - NEXTCLOUD_DATADIR=/mnt/ncdata # Allows to set the host directory for Nextcloud's datadir. See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
      # - NEXTCLOUD_MOUNT=/mnt/ # Allows the Nextcloud container to access the chosen directory on the host. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host
      # - NEXTCLOUD_UPLOAD_LIMIT=10G # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-upload-limit-for-nextcloud
      # - NEXTCLOUD_MAX_TIME=3600 # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-max-execution-time-for-nextcloud
      # - NEXTCLOUD_MEMORY_LIMIT=512M # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-php-memory-limit-for-nextcloud
      # - NEXTCLOUD_TRUSTED_CACERTS_DIR=/path/to/my/cacerts # CA certificates in this directory will be trusted by the OS of the nexcloud container (Useful e.g. for LDAPS) See See https://github.com/nextcloud/all-in-one#how-to-trust-user-defiend-certification-authorities-ca
      # - NEXTCLOUD_STARTUP_APPS=deck tasks calendar contacts # Allows to modify the Nextcloud apps that are installed on starting AIO the first time. See https://github.com/nextcloud/all-in-one#how-to-change-the-nextcloud-apps-that-are-installed-on-the-first-startup
      # - NEXTCLOUD_ADDITIONAL_APKS=imagemagick # This allows to add additional packages to the Nextcloud container permanently. Default is imagemagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-packets-permanently-to-the-nextcloud-container
      # - NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS=imagick # This allows to add additional php extensions to the Nextcloud container permanently. Default is imagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-php-extensions-permanently-to-the-nextcloud-container
      # - TALK_PORT=3478 # This allows to adjust the port that the talk container is using.

  # # Optional: Caddy reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
  # # You can find further examples here: https://github.com/nextcloud/all-in-one/discussions/588
  # caddy:
  #   image: caddy:alpine
  #   restart: always
  #   container_name: caddy
  #   volumes:
  #     - ./Caddyfile:/etc/caddy/Caddyfile
  #     - ./certs:/certs
  #     - ./config:/config
  #     - ./data:/data
  #     - ./sites:/srv
  #   network_mode: "host"
```

This is what I ran

```yaml
version: "3.8"

#Ran this first to create the link for the data directory.
#docker volume create --driver local --name nextcloud_aio_nextcloud_datadir -o device="/host_mnt/j/DockerDesktop/NextCloud_aio/data" -o type="none" -o o="bind"
#docker volume create --driver local --name nextcloud_aio_backupdir -o device="/host_mnt/j/DockerDesktop/NextCloud_aio/backup" -o type="none" -o o="bind"

volumes:
  nextcloud_aio_mastercontainer:
    name: nextcloud_aio_mastercontainer # This line is not allowed to be changed

services:
  nextcloud:
    image: nextcloud/all-in-one:beta # Must be changed to 'nextcloud/all-in-one:latest-arm64' when used with an arm64 CPU
    restart: always
    container_name: nextcloud-aio-mastercontainer # This line is not allowed to be changed
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config # This line is not allowed to be changed
      - //var/run/docker.sock:/var/run/docker.sock:ro # May be changed on macOS, Windows or docker rootless. See the applicable documentation
    ports:
      #- 80:80 # Can be removed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      - 8081:8080
      #- 8443:8443 # Can be removed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
    environment: # Is needed when using any of the options below
      - APACHE_PORT=11000 # Is needed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # - APACHE_IP_BINDING=127.0.0.1 # Should be set when running behind a reverse proxy that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      #- NEXTCLOUD_TRUSTED_DOMAINS=nc.modi-family.com 192.168.1.100 # Your domain name + proxy host IP
      #- TRUSTED_PROXIES=192.168.1.100 # proxy host IP
      - TALK_PORT=3478 # This allows to adjust the port that the talk container is using.
      - NEXTCLOUD_DATADIR=nextcloud_aio_nextcloud_datadir # Allows to set the host directory for Nextcloud's datadir. See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
      # - NEXTCLOUD_MOUNT=/mnt/ # Allows the Nextcloud container to access the chosen directory on the host. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host
      # - DOCKER_SOCKET_PATH=/var/run/docker.sock # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail.
      # - DISABLE_BACKUP_SECTION=true # Setting this to true allows to hide the backup section in the AIO interface.
      # - NEXTCLOUD_UPLOAD_LIMIT=10G # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-upload-limit-for-nextcloud
      # - NEXTCLOUD_MAX_TIME=3600 # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-max-execution-time-for-nextcloud
      # - TRUSTED_CACERTS_DIR=/path/to/my/cacerts # CA certificates in this directory will be trusted by the OS of the nexcloud container (Useful e.g. for LDAPS) See See https://github.com/nextcloud/all-in-one#how-to-trust-user-defiend-certification-authorities-ca
      # - COLLABORA_SECCOMP_DISABLED=false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
      - SKIP_DOMAIN_VALIDATION=true
```

### NextCloud Configration File

Not sure if you need this, but this is my config file for nextcloud after I get it running. This sits in app/config/config.php. It's deisnged to use the cache (redis), my gmail for sending emails to people, and for external access. I manage external access using Nginx proxy manager.

```php
<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'redis',
    'password' => 'modi3885',
    'port' => 6379,
  ),
  'instanceid' => 'ocac9obwdny3',
  'passwordsalt' => 'DTZBbvR+SvYhuxecBZ3rrx9QQWRHfF',
  'secret' => '0UV8PobIDmd1+rmKTvhnNgGcaCnfEAsQ2X2JNpJLtZ8eUep5',
  'trusted_domains' => 
  array (
    0 => 'localhost:8888',
    1 => '192.168.1.100:8888',
    2 => 'nc.parthmodi.com',
    3 => 'nextcloud.parthmodi.com',
    4 => 'files.parthmodi.com',
    5 => 'cloud.parthmodi.com',
    6 => 'nc.modi-family.com',
    7 => 'nextcloud.modi-family.com',
    8 => 'files.modi-family.com',
    9 => 'cloud.modi-family.com',
  ),
  'trusted_proxies' => 
  array (
    0 => '192.168.1.100',
    1 => 'nc.parthmodi.com',
    2 => 'nextcloud.parthmodi.com',
    3 => 'files.parthmodi.com',
    4 => 'cloud.parthmodi.com',
    5 => 'nc.modi-family.com',
    6 => 'nextcloud.modi-family.com',
    7 => 'files.modi-family.com',
    8 => 'cloud.modi-family.com',
  ),
  'allow_local_remote_servers' => true,
  'check_data_directory_permissions' => false,
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '25.0.2.3',
  'overwrite.cli.url' => 'https://cloud.modi-family.com',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'passw0rd',
  'installed' => true,
  'app_install_overwrite' => 
  array (
    0 => 'dashboard',
    1 => 'ocr',
    2 => 'files_ebookreader',
    3 => 'groupfolders',
    4 => 'files_mindmap',
    5 => 'files_fulltextsearch_tesseract',
    6 => 'files_fulltextsearch',
    7 => 'fulltextsearch_elasticsearch',
    8 => 'fulltextsearch',
    9 => 'drawio',
    10 => 'files_reader',
    11 => 'apporder',
    12 => 'bruteforcesettings',
    13 => 'side_menu',
    14 => 'nextbackup',
    15 => 'onlyoffice',
    16 => 'tasks',
    17 => 'occweb',
  ),
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 0,
  'log.condition' => 
  array (
    'apps' => 
    array (
      0 => 'admin_audit',
    ),
  ),
  'defaultapp' => 'apporder',
  'mail_domain' => 'modi-family.com',
  'mail_from_address' => 'admin',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'modifamilyapp@gmail.com',
  'mail_smtppassword' => 'thtwwuoaopwdmovy',
  'mail_smtpsecure' => 'tls',
);

```