Cron Job - Something wrong / Config folder write issue

Issue being faced:
I am getting the following error message in the Settings → Basic Settings page of my Nextcloud:
Last job execution ran 1 hour ago. Something seems wrong.

Logs:

  • Admin > Logging: No error message
  • Docker logs
cron_1   | 2022-01-09T01:30:00.327634552Z crond: wakeup dt=60
cron_1   | 2022-01-09T01:30:00.327667750Z crond: file www-data:
cron_1   | 2022-01-09T01:30:00.327673494Z crond:  line php -f /var/www/html/cron.php
cron_1   | 2022-01-09T01:30:00.327676733Z crond:  job: 0 php -f /var/www/html/cron.php
cron_1   | 2022-01-09T01:30:00.329680776Z crond: child running /bin/bash
cron_1   | 2022-01-09T01:30:00.329698928Z crond: USER www-data pid   8 cmd php -f /var/www/html/cron.php
cron_1   | 2022-01-09T01:30:00.455511955Z Cannot write into "config" directory!
cron_1   | 2022-01-09T01:30:00.455536456Z This can usually be fixed by giving the webserver write access to the config directory.
cron_1   | 2022-01-09T01:30:00.455541337Z
cron_1   | 2022-01-09T01:30:00.455544367Z But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
cron_1   | 2022-01-09T01:30:00.455547575Z See https://docs.nextcloud.com/server/23/go.php?to=admin-config

So I think the ‘Cannot write into “config” directory!’ is causing the error message in Basic Settings. However I cant seem to resolve the permission issue. I checked to make sure the config folder has the right owner and permission but it is still causing issue.

user@external:~/docker/config$ sudo docker exec config_app_1 ls -n /var/www/html/config
total 100
-rw-r--r-- 1 33 0    60 Dec 29 00:25 apache-pretty-urls.config.php
-rw-r--r-- 1 33 0    70 Dec 29 00:25 apcu.config.php
-rw-r--r-- 1 33 0   377 Dec 29 00:25 apps.config.php
-rw-r--r-- 1 33 0  1597 Jan  9 01:13 config.php
-rw-r--r-- 1 33 0 62977 Dec 29 00:25 config.sample.php
-rw-r--r-- 1 33 0   484 Dec 29 00:25 redis.config.php
-rw-r--r-- 1 33 0   798 Dec 29 00:25 reverse-proxy.config.php
-rw-r--r-- 1 33 0  1330 Dec 29 00:25 s3.config.php
-rw-r--r-- 1 33 0   944 Dec 29 00:25 smtp.config.php
-rw-r--r-- 1 33 0  1103 Dec 29 00:25 swift.config.php

user@external:~/docker/config$ sudo docker exec config_app_1 ls -n /var/www/html
total 152
drwxr-xr-x 44 33  0  4096 Dec 29 00:25 3rdparty
-rw-r--r--  1 33  0 19327 Dec 29 00:25 AUTHORS
-rw-r--r--  1 33  0 34520 Dec 29 00:25 COPYING
drwxr-xr-x 48 33  0  4096 Dec 29 00:25 apps
drwxrwxrwx  2 33 33  4096 Jan  9 01:13 config
-rw-r--r--  1 33  0  3924 Dec 29 00:25 console.php
drwxr-xr-x 22 33  0  4096 Dec 29 00:25 core
-rw-r--r--  1 33  0  5226 Dec 29 00:25 cron.php
drwxr-xr-x  3 33  0  4096 Dec 29 00:27 custom_apps
drwxrwx---  5 33 33  4096 Dec 29 00:33 data
-rw-r--r--  1 33  0   156 Dec 29 00:25 index.html
-rw-r--r--  1 33  0  3455 Dec 29 00:25 index.php
drwxr-xr-x  6 33  0  4096 Dec 29 00:25 lib
-rwxr-xr-x  1 33  0   283 Dec 29 00:25 occ
drwxr-xr-x  2 33  0  4096 Dec 29 00:25 ocm-provider
drwxr-xr-x  2 33  0  4096 Dec 29 00:25 ocs
drwxr-xr-x  2 33  0  4096 Dec 29 00:25 ocs-provider
-rw-r--r--  1 33  0  3139 Dec 29 00:25 public.php
-rw-r--r--  1 33  0  5340 Dec 29 00:25 remote.php
drwxr-xr-x  4 33  0  4096 Dec 29 00:25 resources
-rw-r--r--  1 33  0    26 Dec 29 00:25 robots.txt
-rw-r--r--  1 33  0  2452 Dec 29 00:25 status.php
drwxr-xr-x  3 33  0  4096 Dec 29 00:25 themes
-rw-r--r--  1 33  0   383 Dec 29 00:25 version.php

user@external:~/docker/config$ sudo docker exec config_app_1 id -u www-data
33

This is my docker-compose:


version: '2'

volumes:
  nextcloud:
  db:

services:
  db:
    image: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-file-per-table=1 --skip-innodb-read-only-compressed
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD= ***redacted***
      - MYSQL_PASSWORD= ***redacted***
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    network_mode: bridge

  redis:
    image: redis:alpine
    restart: always

  app:
    image: nextcloud
    restart: always
    ports:
      - 8888:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - /var/nextcloud/config:/var/www/html/config
      - /var/nextcloud/data:/var/www/html/data
      - /tmp/nextcloud:/var/www/html/core/skeleton
    environment:
      - MYSQL_PASSWORD= ***redacted***
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - NEXTCLOUD_TRUSTED_DOMAINS= ***redacted***
      - APACHE_DISABLE_REWRITE_IP=1
      - TRUSTED_PROXIES=172.17.0.1
      - OVERWRITEHOST= ***redacted***
      - OVERWRITEPROTOCOL=https
      - OVERWRITECLIURL= ***redacted***
      - OVERWRITEWEBROOT=/
    network_mode: bridge

  cron:
    image: nextcloud
    restart: always
    volumes:
      - nextcloud:/var/www/html
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis

Any help is appreciated!

run ls -l instead of ls -n. Is the config directory owned by www-data? Is 33 the uid of www-data?

Try this:

sudo -u www-data touch /var/www/html/test

(remove the test file thereafter) Does it work? It should if the credentials are ok.

Yes, 33 is the uid of www-data.

Tried your command (a variation since it is in docker container) and it works fine.

user@external:~/docker/config$ sudo docker exec --user www-data config_app_1 touch /var/www/html/test

user@external:~/docker/config$ sudo docker exec --user www-data config_app_1 ls -l /var/www/html
total 152
drwxr-xr-x 44 www-data root      4096 Dec 29 00:25 3rdparty
-rw-r--r--  1 www-data root     19327 Dec 29 00:25 AUTHORS
-rw-r--r--  1 www-data root     34520 Dec 29 00:25 COPYING
drwxr-xr-x 48 www-data root      4096 Dec 29 00:25 apps
drwxrwxrwx  2 www-data www-data  4096 Jan  9 01:13 config
-rw-r--r--  1 www-data root      3924 Dec 29 00:25 console.php
drwxr-xr-x 22 www-data root      4096 Dec 29 00:25 core
-rw-r--r--  1 www-data root      5226 Dec 29 00:25 cron.php
drwxr-xr-x  3 www-data root      4096 Dec 29 00:27 custom_apps
drwxrwx---  5 www-data www-data  4096 Dec 29 00:33 data
-rw-r--r--  1 www-data root       156 Dec 29 00:25 index.html
-rw-r--r--  1 www-data root      3455 Dec 29 00:25 index.php
drwxr-xr-x  6 www-data root      4096 Dec 29 00:25 lib
-rwxr-xr-x  1 www-data root       283 Dec 29 00:25 occ
drwxr-xr-x  2 www-data root      4096 Dec 29 00:25 ocm-provider
drwxr-xr-x  2 www-data root      4096 Dec 29 00:25 ocs
drwxr-xr-x  2 www-data root      4096 Dec 29 00:25 ocs-provider
-rw-r--r--  1 www-data root      3139 Dec 29 00:25 public.php
-rw-r--r--  1 www-data root      5340 Dec 29 00:25 remote.php
drwxr-xr-x  4 www-data root      4096 Dec 29 00:25 resources
-rw-r--r--  1 www-data root        26 Dec 29 00:25 robots.txt
-rw-r--r--  1 www-data root      2452 Dec 29 00:25 status.php
-rw-r--r--  1 www-data www-data     0 Jan  9 19:35 test
drwxr-xr-x  3 www-data root      4096 Dec 29 00:25 themes
-rw-r--r--  1 www-data root       383 Dec 29 00:25 version.php

Figured out why.

I mapped the /var/next/config folder in the app container to my host but didnt do it for my cron container.

So when cron tried to run, it couldnt see the contents of the config folder.