Upgrade from 19.0.10 to 20.0.9 failed: Yet another "Could not unlink..." Problem

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

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:

Nextcloud version (eg, 20.0.5): 19.0.10
Operating system and version (eg, Ubuntu 20.04): CentOS7
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.6 (CentOS)
PHP version (eg, 7.4): PHP 7.4.16

The issue you are facing:
I have successfully run the update from NC 18 to 19 via CLI, but the next upgrade from 19 to 20 fails at the ‘delete old files’ step.
I have read a number of posts and also recalled from a past upgrade issue that ownership in the HTTP folder can be an issue, but I have checked this and recursively adapted all ownerships to the apache user, but the issue remains. I have run the upgrade now 3 times, but it is stuck at the same point (it was stuck at the same step, but a different file (robots.txt) before, which I deleted and then it moved to this one.

Any help highly Dieser Text wird ausgeblendetappreciated!

From my perspective all rights and owners of the files in question look fine:

[root@11no updater]# sudo -u apache /usr/bin/php updater.phar
Nextcloud Updater - version: v19.0.3-8-gbfdc40b
Current version is 19.0.10.
Update to Nextcloud 20.0.9 available. (channel: "stable")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-20.0.9.zip
Open changelog ↗

Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done
Start update? [y/N] y

Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.

[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[ ] Delete old files ...PHP Warning: unlink(/var/www/html/updater/../console.php): Permission denied in phar:///var/www/html/updater/updater.phar/lib/Updater.php on line 866

[✘] Delete old files failed

Could not unlink: /var/www/html/updater/../console.php
Update failed. To resume or retry just execute the updater again.

[root@11no updater]# cd ..
[root@11no html]# ls -l
insgesamt 140
drwxr-xr-x 41 apache apache 4096 26. Apr 16:54 **3rdparty**
drwxr-xr-x 8 apache apache 4096 26. Apr 20:46 **apps**
-rw-r--r-- 1 apache apache 16522 8. Apr 13:18 AUTHORS
drwxr-xr-x 3 apache apache 4096 26. Apr 20:46 **config**
-rw-r--r-- 1 apache apache 3967 8. Apr 13:18 console.php
-rw-r--r-- 1 apache apache 34520 8. Apr 13:18 COPYING
drwxr-xr-x 23 apache apache 4096 26. Apr 16:54 **core**
-rw-r--r-- 1 apache apache 5140 8. Apr 13:18 cron.php
drwxr-x--- 9 apache apache 4096 26. Apr 15:21 **data**
-rw-r--r-- 1 apache apache 156 8. Apr 13:18 index.html
-rw-r--r-- 1 apache apache 57 28. Apr 20:01 index.php
drwxr-xr-x 6 apache apache 4096 26. Apr 16:54 **lib**
-rwxr-xr-x 1 apache apache 283 8. Apr 13:18 **occ**
drwxr-xr-x 2 apache apache 4096 26. Apr 16:54 **ocm-provider**
drwxr-xr-x 2 apache apache 4096 26. Apr 16:54 **ocs**
drwxr-xr-x 2 apache apache 4096 26. Apr 16:54 **ocs-provider**
-rw-r--r-- 1 apache apache 57 28. Apr 20:01 public.php
-rw-r--r-- 1 apache apache 57 28. Apr 20:01 remote.php
-rw-r--r-- 1 apache apache 57 28. Apr 20:01 status.php
drwxr-xr-x 3 apache apache 4096 26. Apr 20:46 **themes**
drwxr-xr-x 3 apache apache 4096 27. Apr 08:20 **updater**
-rw-r--r-- 1 apache apache 364 8. Apr 13:20 version.php

[root@11no html]# cd updater/
[root@11no updater]# ls -l

insgesamt 660
-rw-r--r-- 1 apache apache 66296 8. Apr 13:18 index.php
drwxr-x--- 2 apache apache 4096 27. Aug 2020 **updater**
-rw-r--r-- 1 apache apache 600602 8. Apr 13:18 updater.phar

Is this the first time you’ve seen this error? Y

Steps to replicate it:

  1. Run upgrade from CLI

The output of your Nextcloud log in Admin > Logging:

Nextcloud is down

Output of Updater.log:

2021-04-28T20:01:26+0000 IdL4mweIuL [info] executeStep request for step "9"
2021-04-28T20:01:26+0000 IdL4mweIuL [info] startStep("9")
2021-04-28T20:01:26+0000 IdL4mweIuL [info] deleteOldFiles()
2021-04-28T20:01:26+0000 IdL4mweIuL [error] executeStep request failed with other exception
2021-04-28T20:01:26+0000 IdL4mweIuL [error] Exception: Exception
Message: Could not unlink: /var/www/html/updater/../console.php
Code:0
Trace:
#0 phar:///var/www/html/updater/updater.phar/lib/UpdateCommand.php(381): NC\Updater\Updater->deleteOldFiles()
#1 phar:///var/www/html/updater/updater.phar/lib/UpdateCommand.php(233): NC\Updater\UpdateCommand->executeStep(9)
#2 phar:///var/www/html/updater/updater.phar/vendor/symfony/console/Command/Command.php(256): NC\Updater\UpdateCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component
\Console\Output\ConsoleOutput))
#3 phar:///var/www/html/updater/updater.phar/vendor/symfony/console/Application.php(820): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\
Component\Console\Output\ConsoleOutput))
#4 phar:///var/www/html/updater/updater.phar/vendor/symfony/console/Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(NC\Updater\UpdateCommand), Object(Symfony\Component\Co
nsole\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 phar:///var/www/html/updater/updater.phar/vendor/symfony/console/Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Co
mponent\Console\Output\ConsoleOutput))
#6 phar:///var/www/html/updater/updater.phar/updater.php(10): Symfony\Component\Console\Application->run()
#7 /var/www/html/updater/updater.phar(10): require('phar:///var/www...')
#8 {main}
File:phar:///var/www/html/updater/updater.phar/lib/Updater.php
Line:868

2021-04-28T20:01:26+0000 IdL4mweIuL [info] rollbackChanges("9")
2021-04-28T20:01:26+0000 IdL4mweIuL [info] unlink .step
2021-04-28T20:01:26+0000 IdL4mweIuL [info] rollbackChanges - step >= 7
2021-04-28T20:01:26+0000 IdL4mweIuL [info] end of  rollbackChanges()

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => '11no....',
  ),
  'datadirectory' => '/var/www/html/data',
  'overwrite.cli.url' => 'http://11no....',
  'dbtype' => 'mysql',
  'version' => '19.0.10.1',
  'installed' => true,
  'maintenance' => true,
  'theme' => '',
  'loglevel' => 0,
  'filelocking.enabled' => false,
  'dbname' => 'nextcloud',
  'dbhost' => '127.0.0.1',
  'dbuser' => '',
  'dbpassword' => '',
  'mysql.utf8mb4' => true,
);

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

Not sure where to find this in my setup

Could be a file which is not owned by user Apache and therefore cannot be deleted.

Thanks Sanook!

Actually it was really something like that.
I re-did the permissions of the whole NextCloud directory (the ownership was already ensured):
find nextcloud/ -type d -exec chmod 750 {} ;
find nextcloud/ -type f -exec chmod 640 {} ;
And additionally also gave the apache / www-data owner ownership to the www top folder of Apache according to this tip on Reddit:

Not sure what exactly did it, but then it worked!

Thanks and maybe it’ll also help someone else.

Best regards!