Update from 17.0.8 to 18.0.7 fails: problems locking config.php

Nextcloud version: 18.0.7
Operating system and version: Ubuntu 20.04
Apache or nginx version: Apache2 2.4.41-4ubuntu3
PHP version: 7.4.3

I am working on bringing my old Nextcloud 15 installation to a current level. Updates to 16 and then to 17.0.8 have succeeded. The update to 18.0.7 is failing on the occ-upgrade-stage:

root@web:/var/www/owncloud# sudo -u www-data php occ upgrade
An unhandled exception has been thrown:
Exception: Could not acquire a shared lock on the config file /var/www/owncloud/config/config.php in /var/www/owncloud/lib/private/Config.php:211
Stack trace:
#0 /var/www/owncloud/lib/private/Config.php(64): OC\Config->readData()
#1 /var/www/owncloud/lib/base.php(145): OC\Config->__construct()
#2 /var/www/owncloud/lib/base.php(582): OC::initPaths()
#3 /var/www/owncloud/lib/base.php(1089): OC::init()
#4 /var/www/owncloud/console.php(48): require_once('/var/www/ownclo...')
#5 /var/www/owncloud/occ(11): require_once('/var/www/ownclo...')

I have followed the Nextcloud doc for manual upgrading: Rename old directory, extract zip into new directory, copy config.php and /data, run chown, then run occ upgrade - which is where the above error now occurs.

config.php /var/www/owncloud/config:

$CONFIG = array (
  'instanceid' => '51f6b97ddcbb5',
  'passwordsalt' => '66519407bad8c2062e9f66cddb0199',
  'datadirectory' => '/var/www/owncloud/data',
  'dbtype' => 'mysql',
  'version' => '17.0.8.1',
  'dbname' => 'owncloud',
  'dbhost' => 'db.example.com',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'dbuser',
  'dbpassword' => 'dbpassword',
  'installed' => true,
  'loglevel' => '1',
  'log_rotate_size' => 10485760,
  'theme' => '',
  'maintenance' => false,
  'trusted_domains' =>
  array (
    0 => 'www.example.com',
    1 => '192.168.1.103',
  ),
  'share_folder' => '/Shared',
  'mail_domain' => 'example.com',
  'mail_from_address' => 'noreply',
  'mail_smtpdebug' => false,
  'mail_smtpmode' => 'smtp',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
  'logtimezone' => 'Europe/Berlin',
  'overwrite.cli.url' => 'https://www.example.com/owncloud',
  'secret' => 'verysecret',
  'trashbin_retention_obligation' => 'auto',
  'updatechecker' => false,
  'updater.server.url' => 'https://updates.nextcloud.org/server/',
  'updater.release.channel' => 'stable',
  'htaccess.RewriteBase' => '/owncloud',
  'versions_retention_obligation' => 'auto, 90',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'mail.example.com',
  'mail_smtpport' => '25',
  'mail_smtpname' => 'noreply@example.com',
  'mail_smtppassword' => 'password',
);

root@web:/var/www/owncloud/config# ls -la
total 107
drwxr-x---  2 www-data www-data     6 Jul 19 17:05 .
drwxr-x--- 14 www-data www-data    28 Jul 19 17:06 ..
-rw-r-----  1 www-data www-data   495 Jul 15 22:01 .htaccess
-rw-r-----  1 www-data www-data     0 Jul 15 22:01 CAN_INSTALL
-rw-r-----  1 www-data www-data  1650 Jul 19 17:05 config.php
-rw-r-----  1 www-data www-data 54880 Jul 15 22:01 config.sample.php

I’m a bit lost as to what the root cause might be. Any help/pointers would be appreciated!

This has to do with the setting:
‘config_is_read_only’ => either false or true,
inside the config.php

From the manual:
In certain environments it is desired to have a read-only configuration file.

When this switch is set to true Nextcloud will not verify whether the configuration is writable. However, 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 for the update process.

Do a:
chmod 644 /var/www/owncloud/config/config.php
before upgrading and the upgrade should finish successfully.

I think you must use.

sudo -u www-data php updater/updater.phar

part " Using the command line based updater":

https://docs.nextcloud.com/server/19/admin_manual/maintenance/update.html

  1. Once all steps are executed the updater will ask you a final question: “Should the “occ upgrade” command be executed?”.

For running a Command line based upgrade through the built-in updater
sudo -u www-data php updater/updater.phar is correct.

@Nerd is upgrading manually. Therefore using
sudo -u www-data php occ upgrade is correct:

https://docs.nextcloud.com/server/19/admin_manual/maintenance/manual_upgrade.html

@Tamsy: Thanks for looking into this. Unfortunately, the chmod hasn’t really helped:

# chmod 644 config.php

root@web:/var/www/owncloud/config# ls -al
total 107
drwxr-x---  2 www-data www-data     6 Jul 19 17:05 .
drwxr-x--- 14 www-data www-data    28 Jul 19 17:06 ..
-rw-r-----  1 www-data www-data   495 Jul 15 22:01 .htaccess
-rw-r-----  1 www-data www-data     0 Jul 15 22:01 CAN_INSTALL
-rw-r--r--  1 www-data www-data  1650 Jul 19 17:05 config.php
-rw-r-----  1 www-data www-data 54880 Jul 15 22:01 config.sample.php

root@web:/var/www/owncloud/config# cd ..
root@web:/var/www/owncloud# sudo -u www-data php occ upgrade
An unhandled exception has been thrown:
Exception: Could not acquire a shared lock on the config file /var/www/owncloud/config/config.php in /var/www/owncloud/lib/private/Config.php:211
Stack trace:
#0 /var/www/owncloud/lib/private/Config.php(64): OC\Config->readData()
#1 /var/www/owncloud/lib/base.php(145): OC\Config->__construct()
#2 /var/www/owncloud/lib/base.php(582): OC::initPaths()
#3 /var/www/owncloud/lib/base.php(1089): OC::init()
#4 /var/www/owncloud/console.php(48): require_once('/var/www/ownclo...')
#5 /var/www/owncloud/occ(11): require_once('/var/www/ownclo...') 

As config.php is owned by www-data:www.data and the script is run as www-data, the script should be writeable in any case?

is your config.php or the folder containing it mounted via smb or NFS?

Related issue: https://github.com/nextcloud/server/issues/19829

Yes, all websites - including Nextcloud - are on an NFS share.

OK, this seems to be the common theme here: config.php is on a mounted SMB or NFS share

Ok, hm. Transferring things locally is difficult - the local machine is a VM which does not have enough storage itself…

yeah, that doesn’t seem like a solution.
This is the workaround I used:
After the updater finished and asked for occ upgrade I said no and then proceeded to delete /var/www/nextcloud/config/CAN_INSTALL and copied my backup of config.php back to /var/www/nextcloud/config/config.php. Then occ upgrade went through with no problems.
But careful: In that short timeframe between finishing the updater and removing the CAN_INSTALL file everyone visiting the site can see the web installer, so you better stop your webserver right before the updater or deactivate the backend servers in your load balancer.

Thanks, I’ve marked your post as solution. I’m not exactly sure which steps helped in which order, but at some point after fiddling around with the config (which here was never deleted) and CAN_INSTALL, restarting statd on the NFS server, and playing around with some more things, occ upgrade went through.

By the way, nextcloud here is now on 19.0.1, as the upgrade from 18.0.7 to 19.0.1 again was a piece of cake, no probs…