Nextcloud

Via docker-compose

MariaDB hosted on a Docker container

Id

Reference

License

1

https://docs.nextcloud.com/server/20/admin_manual/configuration_database/linux_database_configuration.html

CC BY 3.0 1

2

https://faun.pub/deploy-nextcloud-with-docker-compose-traefik-2-postgresql-and-redis-fd1ffc166173

unknown

3

https://techoverflow.net/2020/12/01/how-to-backup-data-from-docker-compose-mariadb-container-using-mysqldump/

unknown

Run as user

root

  1. follow the Docker instructions

  2. create the usual jobs directories

    mkdir -p /home/jobs/scripts/by-user/root/docker/nextcloud
    chmod 700 /home/jobs/scripts/by-user/root/nextcloud
    cd /home/jobs/scripts/by-user/root/docker/nextcloud
    
  3. create a Docker compose file

    /home/jobs/scripts/by-user/root/docker/nextcloud/docker-compose.yml
     1# Either select the MariaDB or Postgres configurations.
     2
     3# MariaDB hosted on a Docker container.
     4version: '2'
     5
     6volumes:
     7  nextcloud:
     8  db:
     9  redis:
    10
    11services:
    12  # See
    13  # https://help.nextcloud.com/t/mariadb-upgrade-from-10-5-11-to-10-6-causes-internal-server-error/120585
    14  db:
    15    hostname: db
    16    image: mariadb:10.5.11
    17    restart: always
    18    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    19    volumes:
    20      - ./db:/var/lib/mysql
    21    environment:
    22      - MYSQL_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD}
    23      - MYSQL_PASSWORD=${DATABASE_PASSWORD}
    24      - MYSQL_DATABASE=nextcloud
    25      - MYSQL_USER=nextcloud
    26
    27  app:
    28    image: nextcloud:production
    29    restart: always
    30    ports:
    31      - 4005:80
    32    links:
    33      - db
    34      - redis
    35    volumes:
    36      - ${DATA_PATH}:/var/www/html/data
    37      - ./nextcloud:/var/www/html
    38    environment:
    39      - MYSQL_PASSWORD=${DATABASE_PASSWORD}
    40      - MYSQL_DATABASE=nextcloud
    41      - MYSQL_USER=nextcloud
    42      - MYSQL_HOST=db
    43      - APACHE_DISABLE_REWRITE_IP=1
    44      - TRUSTED_PROXIES=127.0.0.1
    45      - OVERWRITEHOST=${FQDN}
    46      - OVERWRITEPROTOCOL=https
    47
    48  redis:
    49    image: redis:6.2.5
    50    restart: always
    51    hostname: redis
    52    volumes:
    53      - redis:/var/lib/redis
    

    Nota

    Replace DATABASE_ROOT_PASSWORD, DATABASE_PASSWORD and FQDN with appropriate values.

  4. create a Systemd unit file. See also the Docker compose services section

    /home/jobs/services/by-user/root/docker-compose.nextcloud.service
     1[Unit]
     2Requires=docker.service
     3Requires=network-online.target
     4After=docker.service
     5After=network-online.target
     6
     7[Service]
     8Type=simple
     9WorkingDirectory=/home/jobs/scripts/by-user/root/docker/nextcloud
    10
    11ExecStart=/usr/bin/docker-compose up --remove-orphans
    12ExecStop=/usr/bin/docker-compose down --remove-orphans
    13
    14Restart=always
    15
    16[Install]
    17WantedBy=multi-user.target
    
  5. run the deploy script

  6. modify the reverse proxy port of your webserver configuration with 4005

File scanner

Run as user

root

  1. create another Systemd unit file that will enable nextcloud to periodically scan for new files if added by external sources

    /home/jobs/services/by-user/root/scan-files-nextcloud.service
     1[Unit]
     2Requires=docker-compose.nextcloud.service
     3Requires=network-online.target
     4After=docker-compose.nextcloud.service
     5After=network-online.target
     6
     7[Service]
     8Type=simple
     9WorkingDirectory=/home/jobs/scripts/by-user/root/docker/nextcloud
    10Restart=no
    11
    12# Scan all new files.
    13ExecStart=/usr/bin/bash -c '/usr/bin/docker-compose exec -T --user www-data app php occ files:scan --all'
    
  2. create a Systemd timer file

    /home/jobs/services/by-user/root/scan-files-nextcloud.timer
    1[Unit]
    2Description=Once every week scan-files-nextcloud
    3
    4[Timer]
    5OnCalendar=weekly
    6Persistent=true
    7
    8[Install]
    9WantedBy=timers.target
    

Migration from MariaDB on a container to PostgreSQL in host

Run as user

root

  1. check that your PostgreSQL is fully configured and running

  2. add an entry in the pg_hba.conf file

    /etc/postgresql/13/main/pg_hba.conf
    host    nextclouddb   nextcloud   172.16.0.0/16  scram-sha-256
    
  3. change this setting in postgresql.conf

    /etc/postgresql/13/main/postgresql.conf
    listen_addresses = '*'
    
  4. restart Postgres

    systemctl restart postgresql.service
    
  5. stop the Nextcloud container

    systemctl stop docker-compose.nextcloud.service
    
  6. convert the database type. You will be prompted for the database password

    docker-compose exec --user www-data app php occ db:convert-type --all-apps pgsql ${DATABASE_USER} ${DATABASE_HOST} ${DATABASE_NAME}
    

    The Docker container must now comunicate with the PostgreSQL instance running on bare metal. The variables used here refer to the PostgreSQL instance.

  7. use this Docker compose file instead. See also the Docker compose services section

    /home/jobs/scripts/by-user/root/docker/nextcloud/docker-compose.yml
    56version: '2'
    57
    58volumes:
    59  nextcloud:
    60  redis:
    61
    62services:
    63  app:
    64    image: nextcloud:production
    65    restart: always
    66    ports:
    67      - 4005:80
    68    links:
    69      - redis
    70    volumes:
    71      - /data/media/DOCKER_VOLUMES/nextcloud:/var/www/html/data
    72      - ./nextcloud:/var/www/html
    73    environment:
    74      - REDIS_HOST=redis
    75      - POSTGRES_DB=${DATABASE_NAME}
    76      - POSTGRES_USER=${DATABASE_USER}
    77      - POSTGRES_HOST=${DATABASE_HOST}
    78      - POSTGRES_PASSWORD=${DATABASE_PASSWORD}
    79      - APACHE_DISABLE_REWRITE_IP=1
    80      - TRUSTED_PROXIES=127.0.0.1
    81      - OVERWRITEHOST=${FQDN}
    82      - OVERWRITEPROTOCOL=https
    83
    84  redis:
    85    image: redis:6.2.5
    86    restart: always
    87    hostname: redis
    88    volumes:
    89      - redis:/var/lib/redis
    

    Nota

    Replace DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST and FQDN with appropriate values. DATABASE_HOST may be different from FQDN if PostgreSQL is not reachable through Internet or is running on a different machine.

  8. run the deploy script

Footnotes

1

Copyright (c) Nextcloud contributors