[Solved] Error while trying to initialise the database

I am trying to install Nextcloud on a pc running Ubuntu server 20.04. I am running Nextcloud using Docker and Nginx reverse proxy, as according to the official examples (see the docker-compose below) and have encountered a problem: whenever I clck ‘Finish setup’ on the Nextcloud initial setup page, I get the following error:

Error while trying to initialise the database: An exception occurred while executing 'SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'': SQLSTATE[HY000]: General error: 1018 Can't read dir of './nextcloud/' (errno: 13 "Permission denied")

Looking at the docker logs, I got the following messages:

nginx-proxy_1   | nginx.1    | [My domain here] [My IP adress here] - - [10/Sep/2020:23:58:33 +0000] "GET /data/htaccesstest.txt HTTP/1.1" 301 169 "-" "Nextcloud Server Crawler"
nextcloud_1     | [Thu Sep 10 23:58:33.764366 2020] [access_compat:error] [pid 67] [client [My IP adress here]:0] AH01797: client denied by server configuration: /var/www/html/data/htaccesstest.txt
nginx-proxy_1   | nginx.1    | [My domain here] [My IP adress here] - - [10/Sep/2020:23:58:33 +0000] "GET /data/htaccesstest.txt HTTP/1.1" 403 281 "-" "Nextcloud Server Crawler"
nextcloud_1     | 172.19.0.2 - - [10/Sep/2020:23:58:33 +0000] "GET /data/htaccesstest.txt HTTP/1.1" 403 675 "-" "Nextcloud Server Crawler"
nextcloud_1     | [Thu Sep 10 23:58:33.825230 2020] [access_compat:error] [pid 62] [client [My IP adress here]:0] AH01797: client denied by server configuration: /var/www/html/data/htaccesstest.txt
nginx-proxy_1   | nginx.1    | [My domain here] [My IP adress here] - - [10/Sep/2020:23:58:33 +0000] "GET /data/htaccesstest.txt HTTP/1.1" 403 281 "-" "Nextcloud Server Crawler"
nextcloud_1     | 172.19.0.2 - - [10/Sep/2020:23:58:33 +0000] "GET /data/htaccesstest.txt HTTP/1.1" 403 675 "-" "Nextcloud Server Crawler"
nextcloud_1     | 172.19.0.2 - - [10/Sep/2020:23:58:33 +0000] "POST /index.php HTTP/1.1" 200 3635 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"
nginx-proxy_1   | nginx.1    | [My domain here] [My IP adress here] - - [10/Sep/2020:23:58:33 +0000] "POST /index.php HTTP/2.0" 200 2627 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"

This htaccesstest.txt file doesn’t seem to exist (there is, however, a .htaccess file).

My docker-compose is modified from the https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/mariadb/apache compose file. I also had to run

sudo docker-compose exec nextcloud chown -R www-data:www-data /var/www/html/

in order to fix Nextcloud returning “internal server error” whenever I attempted to access it.

Docker-compose is as follows:

version: '3'

services:
  nextcloud-db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - /data/docker/nextcloud-db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=[My server password here]
      - MYSQL_PASSWORD=[My server password here]
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  nextcloud:
    image: nextcloud:apache
    restart: always
    volumes:
      - /data/docker/nextcloud-db:/var/www/html
    environment:
      - VIRTUAL_HOST=[My domain here]
      - LETSENCRYPT_HOST=[My domain here]
      - LETSENCRYPT_EMAIL=[My email here]
      - MYSQL_HOST=nextcloud-db
      - MYSQL_PASSWORD=[My server password here]
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    depends_on:
      - nextcloud-db
    networks:
      - proxy-tier
      - default

  nginx-proxy:
    build: ./proxy
    restart: always
    ports:
      - 80:80
      - 443:443
    labels:
      com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
    volumes:
      - /data/docker/certs:/etc/nginx/certs:ro
      - /data/docker/nginx-vhost:/etc/nginx/vhost.d
      - /data/docker/nginx:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-tier

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    restart: always
    volumes:
      - /data/docker/certs:/etc/nginx/certs
      - /data/docker/nginx-vhost:/etc/nginx/vhost.d
      - /data/docker/nginx:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - proxy-tier
    depends_on:
      - nginx-proxy

networks:
  proxy-tier:

Found the problem: the Nextcloud directory was read-only for some reason, fixed by running:

sudo docker-compose exec nextcloud chmod -R +rw /var/www/html/nextcloud

Not sure if this is the proper way to do it or not, but it fixed that particular error. Nextcloud still doesn’t work (looks like more permission errors?) but that’s a topic for another thread.