Cannot write into "config" directory! error after upgrading Nextcloud and PHP

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:o

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 35.0.2
  • Operating system and version (e.g., Ubuntu 24.04):
    • Linux 6.12.47+rpt-rpi-v8 aarch64
  • Web server and version (e.g, Apache 2.4.25):
    • Apache 2.4.68
  • PHP version (e.g, 8.3):
    • 8.5.11
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • After Nextcloud and PHP upgrade

Summary of the issue you are facing:

I recently implemented some server hardening steps and moved config directory outside of web root following server documentation. After a little hickup (see this post), I got everything to work smoothly.

Recently, I upgraded Nextcloud to 35.0.2 and in that context also upgraded PHP from 8.3 to 8.5. After upgrading, I get the error message Cannot write into "config" directory! CLI-calls to occ still work as intended.

SetEnv NEXTCLOUD_CONFIG_DIR is set to the correct path and Nextcloud is reading from it when I call occ config:list system

I set folder permissions for /etc/nextcloud to 0750 and to 0640 for the files in it. Owner is www-data:www-data.

I got the instance running by setting

'config_is_read_only' => true,

However, that doesn’t fix my problem. Anybody got any ideas where to look? Thanks!

Steps to replicate it (hint: details matter!):

  1. move config directory outside webroot according to Hardening and security guidance — Nextcloud 36 Administration Manual

  2. Upgrade major versions of Nextcloud and PHP

  3. recieve error Cannot write into “config” directory!

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

PASTE HERE

Web Browser

If the problem is related to the Web interface, open your browser inspector Console and Network tabs while refreshing (reloading) and reproducing the problem. Provide any relevant output/errors here that appear.

PASTE

Web server / Reverse Proxy

The output of your Apache/nginx/system log in /var/log/____:

PASTE HERE

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "serverid": 0,
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "***REMOVED SENSITIVE VALUE***",
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "https:\/\/***REMOVED SENSITIVE VALUE***",
        "overwriteprotocol": "https",
        "dbtype": "mysql",
        "version": "35.0.2.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "theme": "",
        "loglevel": 2,
        "maintenance": false,
        "default_phone_region": "DE",
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_sendmailmode": "smtp",
        "mail_smtpsecure": "ssl",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "maintenance_window_start": 1,
        "memories.db.triggers.fcu": true,
        "memories.exiftool": "\/var\/www\/html\/nextcloud\/apps\/memories\/bin-ext\/eperl-aarch64-glibc",
        "memories.vod.path": "\/var\/www\/html\/nextcloud\/apps\/memories\/bin-ext\/go-vod-aarch64",
        "memories.vod.ffmpeg": "\/usr\/bin\/ffmpeg",
        "memories.vod.ffprobe": "\/usr\/bin\/ffprobe",
        "enabledPreviewProviders": [
            "OC\\Preview\\Image",
            "OC\\Preview\\HEIC",
            "OC\\Preview\\TIFF",
            "OC\\Preview\\Movie"
        ],
        "preview_max_x": 2048,
        "preview_max_y": 2048,
        "defaultapp": "",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": ***REMOVED SENSITIVE VALUE***
        },
        "files.chunked_upload.max_size": 20971520,
        "updater.release.channel": "stable",
        "twofactor_enforced": "true",
        "twofactor_enforced_groups": [],
        "twofactor_enforced_excluded_groups": [],
        "debug": false,
        "updater.secret": "***REMOVED SENSITIVE VALUE***",
        "config_is_read_only": true
    }
}

Apps

Enabled:
  - activity: 8.0.0
  - appstore: 2.0.0
  - bookmarks: 17.0.0
  - bruteforcesettings: 8.0.0
  - calendar: 6.6.2
  - cloud_federation_api: 2.0.0
  - comments: 2.0.0
  - contacts: 8.9.1
  - contactsinteraction: 2.0.0
  - dashboard: 8.0.0
  - dav: 2.0.0
  - federatedfilesharing: 2.0.0
  - files: 3.0.0
  - files_downloadlimit: 5.3.0
  - files_lock: 35.0.1
  - files_pdfviewer: 8.0.0
  - files_reminders: 2.0.0
  - files_sharing: 2.0.0
  - files_trashbin: 2.0.0
  - files_versions: 2.0.0
  - firstrunwizard: 8.0.0
  - logreader: 8.0.0
  - lookup_server_connector: 2.0.0
  - mail: 5.12.4
  - maps: 1.8.0
  - memories: 10.1.0
  - nextcloud_announcements: 7.0.0
  - notes: 6.1.0
  - notifications: 8.0.1
  - oauth2: 2.0.0
  - password_policy: 7.0.0
  - phonetrack: 1.3.5
  - photos: 8.0.0
  - privacy: 7.0.0
  - profile: 2.0.0
  - provisioning_api: 2.0.0
  - recommendations: 8.0.0
  - related_resources: 6.0.0
  - serverinfo: 7.0.0
  - settings: 2.0.0
  - sharebymail: 2.0.0
  - sharing: 1.0.4
  - support: 7.0.0
  - survey_client: 7.0.0
  - suspicious_login: 13.0.0
  - systemtags: 2.0.0
  - tasks: 0.18.1
  - text: 9.0.1
  - theming: 3.0.0
  - twofactor_backupcodes: 2.0.0
  - twofactor_nextcloud_notification: 9.0.0
  - twofactor_totp: 17.1.0
  - updatenotification: 2.0.0
  - viewer: 8.0.0
  - webhook_listeners: 2.0.0
  - workflowengine: 3.0.0
Disabled:
  - admin_audit: 2.0.0
  - app_api: 35.0.0 (installed 32.0.0)
  - camerarawpreviews: 1.1.4 (installed 1.1.4)
  - circles: 35.0.0 (installed 27.0.1)
  - cospend: 4.1.3 (installed 4.1.3)
  - deck: 1.18.5 (installed 1.18.5)
  - encryption: 3.0.1
  - federation: 2.0.0 (installed 1.17.0)
  - files_external: 2.0.0
  - journeys: 0.35.1 (installed 0.35.1)
  - office: 1.1.0 (installed 1.0.0)
  - starrate: 1.3.12 (installed 1.3.12)
  - testing: 1.23.0
  - user_ldap: 2.0.0
  - user_status: 2.0.0 (installed 1.9.0)
  - weather_status: 2.0.0 (installed 1.11.0)

Tips for increasing the likelihood of a response

  • Use the preformatted text formatting option in the editor for all log entries and configuration output.
  • If screenshots are useful, feel free to include them.
    • If possible, also include key error output in text form so it can be searched for.
  • Try to edit log output only minimally (if at all) so that it can be ran through analyzers / formatters by those trying to help you.

I’d say that’s the reason for the error message. You’ve set the config to “read-only.” Makes sense to me that it can’t write to it then.

See also here: Configuration Parameters — Nextcloud 35 Administration Manual

When this switch is set to true, writing to the config file will be forbidden. Therefore, it will not be possible to configure all options via the Web interface. Furthermore, when updating Nextcloud, it is required to make the configuration file writable again and to set this switch to false for the update process.

That’s only a work-around to make the instance accessible at all. If I don’t set that value to true, all I get is this error message (translation by me, the original message is in German):

Cannot write into "config" directory! This can be fixed by granting the webserver access to the config directory. If you want to keep the file config.php read-only, set "config_is_read_only" to true.

Edit to clarify: when I set "config_is_read_only" => true, I do not get this error. I’ll only see the following message in the Security & setup warnings in the administration overview:

Configuration file access rights
The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.

Ah, okay. Strange. Have you checked the ownership and permissions of the config.php file Other than that, I’m afraid I’m out of ideas.

You could try the following commands, just to rule out any ownership or permission issues:

chown -R www-data:www-data /path/to/nextcloud

find /path/to/nextcloud/ -type f -print0 | xargs -0 chmod 0640
find /path/to/nextcloud/ -type d -print0 | xargs -0 chmod 0750

EDIT: Make sure to adjust the paths to match your installation before running these commands, and run them as root or with sudo privileges.

That’s the crazy part: ownership and permissions are all set. Here’s the ls -al output for /etc/nextcloud:

drwxr-xr-x   2 www-data www-data   4096 Oct 19 14:41 .
drwxr-xr-x 147 root     root      12288 Oct 19 09:42 ..
-rw-r-----   1 www-data www-data   3004 Oct 19 14:41 config.php
-rw-r-----   1 www-data www-data 104245 Aug 14 11:48 config.sample.php
-rw-r--r--   1 www-data www-data    665 Oct 19 11:16 .htaccess

After the Nextcloud-upgrade, there was a new config folder in /var/www/html/nextcloud with a new config.php containing a new instance ID. I thought that that maybe messed things up and moved the new folder, but to no avail. Also, the output of occ config:list system shows the content of the correct file, so the configuration does point to the right config.php. www-data just can’t edit it…

Some random ideas:

  • Have you set open-basedir, and is /etc/nextcloud missing from it?
  • Are you sure the PHP pool is running as www-data?
  • If PHP is running with Systemd, there may also be some restrictions on which parts of the system PHP can access or write to.

Tests using PHP but independent of Nextcloud:

sudo -u www-data php -r 'var_dump(is_writable("/etc/nextcloud"), is_writable("/etc/nextcloud/config.php"));'
sudo -u www-data touch /etc/nextcloud/.write-test && sudo -u www-data rm /etc/nextcloud/.write-test

open_basedir is not set, and PHP is running as www-data. The first test returns

bool(true)
bool(true)

Second test runs without error messages. :face_with_spiral_eyes:

Lol, I talked to Claude about this. It made me go through a whole mess of tests. Turns out that the PHP8.5 FPM service is sandboxed. I fixed it by editing php8.5-fpm and adding

[Service]
ReadWritePaths=/etc/nextcloud

Then systemctl restart php8.5-fpm and systemctl restart apache2 and now it works. Wild…