Uprading OwnCloud: Fixing 'could not acquire lock' error

While upgrading OwnCloud to version 8.1, I experienced strange errors:

www-data@server:/var/owncloud$ php occ upgrade
PHP Warning:  flock() expects parameter 1 to be resource, boolean given in /var/o
wncloud/lib/private/config.php on line 201
PHP Stack trace:
PHP   1. {main}() /var/owncloud/occ:0
PHP   2. require_once() /var/owncloud/occ:11
PHP   3. require_once() /var/owncloud/console.php:41
PHP   4. OC::init() /var/owncloud/lib/base.php:1115
PHP   5. OC::initPaths() /var/owncloud/lib/base.php:524
PHP   6. OC\Config->__construct() /var/owncloud/lib/base.php:134
PHP   7. OC\Config->readData() /var/owncloud/lib/private/config.php:61
PHP   8. flock() /var/owncloud/lib/private/config.php:201
An unhandled exception has been thrown:
exception 'Exception' with message 'Could not acquire a shared lock on the config 
file /var/owncloud/config/config.php' in /var/owncloud/lib/private/config.php:202
Stack trace:
#0 /var/owncloud/lib/private/config.php(61): OC\Config->readData()
#1 /var/owncloud/lib/base.php(134): OC\Config->__construct('/var/owncloud/c...')
#2 /var/owncloud/lib/base.php(524): OC::initPaths()
#3 /var/owncloud/lib/base.php(1115): OC::init()
#4 /var/owncloud/console.php(41): require_once('/var/owncloud/l...')
#5 /var/owncloud/occ(11): require_once('/var/owncloud/c...')
#6 {main}

OwnCloud’s user manual did not help, nor did a Google search.

The solution is quite simple.

I had unpacked the tarball using:

daniel@server:~$ sudo tar xjf owncloud-8.1.tar.bz -C /var/owncloud8.1

The unpacked files were owned by nobody:

daniel@server:/var$ ls -l owncloud
drwxr-xr-x 12 nobody   nogroup  4.0K Jul  3 00:32 owncloud

Changing ownership and group to www-data solved the problem!

daniel@server:/var$ sudo chmod -R www-data:www-data owncloud
daniel@server:/var$ sudo chown -R www-data:www-data owncloud

Then, finally, upgrading owncloud worked:

www-data@server:/var/owncloud$ php occ upgrade
ownCloud or one of the apps require upgrade - only a limited number of commands are available
Checked database schema update
Checked database schema update for apps
Updated database
Disabled 3rd-party app: bookmarks
Updating <updater> ...
Updated <updater> to 0.6
Updating <user_ldap> ...
Updated <user_ldap> to 0.6.1
Updating <activity> ...
Updated <activity> to 2.0.1
Updating <files_sharing> ...
Updated <files_sharing> to 0.6.2
Updating <files_trashbin> ...
Updated <files_trashbin> to 0.6.3
Updating <files_versions> ...
Updated <files_versions> to 1.0.6
Update 3rd-party app: bookmarks
Update successful
Maintenance mode is kept active
www-data@server:/var/owncloud$ 

Hope this helps anyone.