What the message looks like
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory. See https://docs.nextcloud.com/server/latest/admin_manual/installation/installation_wizard.html#setting-strong-directory-permissionsCommon causes
- Files were copied or restored as root, so the owner is not
www-data(ornginx,apache). - Permissions are too tight, for example mode 0700 for another user.
- SELinux or AppArmor blocks writing to the directory.
- In Docker, the mounted volume belongs to a different user than the one inside the container.
config_is_read_onlyis set totrueon purpose.
Check
- Owner and permissions of the directory and the file
ls -ld /var/www/nextcloud/config /var/www/nextcloud/config/config.php - Which user runs PHP?
ps -eo user,comm | grep php-fpm | sort -u - Can that user write?
sudo -u www-data test -w /var/www/nextcloud/config && echo writable - Is the config set to read-only?
grep -n config_is_read_only /var/www/nextcloud/config/config.php
Fix
- Give the web server user the directory:
chown -R www-data:www-data /var/www/nextcloud/config. - Set sensible permissions:
chmod 750 /var/www/nextcloud/configandchmod 640 /var/www/nextcloud/config/config.php. - Only
config/,data/,apps/andthemes/need to be writable. Do not make the whole tree writable. - On SELinux, label the directory:
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/config(/.*)?'andrestorecon -R /var/www/nextcloud/config. - In Docker, fix the owner of the volume on the host, or set
config_is_read_onlyback tofalseif it was not meant to be on.
Typical scenario
You unpacked a Nextcloud installation from the old server onto the new one with tar as root and open the site. Instead of the login you get "Cannot write into config directory!". The files now belong to root or to a UID that the new system assigns differently. First check with ls -ld /var/www/nextcloud/config which user owns the directory and compare it with the user PHP runs as.
FAQ
Is it safe to chown the whole Nextcloud folder?
It works, but it is more than needed. Following the admin manual, the web server user only owns the four writable folders, and the code stays read-only for it.
The error appears right after a restore from backup. Why?
Backups often keep numeric user IDs. If the new system uses other IDs, the owner no longer matches. Set the owner again after the restore.
How do I find out which user PHP runs as?
With PHP-FPM, ps -o user= -C php-fpm8.3 shows the worker users, and the pool file has user =. On Debian and Ubuntu it is usually www-data, on RHEL systems often apache or nginx. You need exactly this user for chown.
Why does the updater want write access to much more than config?
The web updater replaces the program files in the Nextcloud folder and therefore needs write access there. If you prefer to keep the code read-only, run the update as the web server user on the command line with sudo -u www-data php updater/updater.phar and manage the permissions yourself.
What does config_is_read_only do?
With 'config_is_read_only' => true in config.php the configuration is deliberately read-only. Settings and apps then cannot be changed through the web interface. For updates and new apps you have to set it to false temporarily.