Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license CC4-BY
posted in category Systems Software / Nextcloud
posted at 18. Jun '23

Upgrading Nextcloud Tips And Tricks

I upgraded Nextcloud from version 25 to version 27 and it was an oddysey full of perils. Afterwards I found a simpler way in a documentation, but regular web search was not much helpful, so it took longer. Who has time to read through the manual? Well, I should have.

  • try to update via web interface before system update, I didn’t do that, maybe it would work
  • Nextcloud 25 supports PHP 7.4
  • Nextcloud 26 supports PHP 8.1 (recommended), 8.2
  • Nextcloud 27 supports PHP 8.1, 8.2 (recommended)
  • Debian 12 upgraded PHP from 7.4 to 8.2
  • do not download releases from https://github.com/nextcloud/server/releases/tag/v26.0.2, they are missing dependencies and require git submodule …shame that releases do not have .git directories….
  • download releases from here https://nextcloud.com/changelog which include dependencies
  • occ cannot upgrade to a new major version (25 -> 26), only web updater or updater.phar can - it downloads and runs occ later
  • to run “web updater” from CLI: sudo -u www-data php updater.phar
  • major versions cannot be skipped, upgrade needs to go through each one (25 -> 26 -> 27)
  • manual upgrade - https://docs.nextcloud.com/server/latest/admin_manual/maintenance/manual_upgrade.html - important page
  • I tried to install an older version of PHP from https://packages.sury.org/php/README.txt, but in the end wasn’t necessary since v26 supported in 8.2
  • run php occ db:add-missing-indices after upgrades

Issues and How to Solve Them

Verifing Integrity Failed

Updater downloads a new version, but integrity check fails.

Downloading
Verifying integrity
Parsing response failed.
Show detailed response

You need to increase maximum memory for a request, change from 128M to 512M. An update has ~300MB. There is also a message in sanity check in admin interface:

root@starz:/etc/php/8.2/fpm# vim php.ini

; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 512M

systemctl restart php8.2-fpm.service

Press “Retry” button. If there is “step in progress” message, remove a lock with:

rm ../nextcloud_data/updater-fdsfasdfa/.step

“Nextcloud is already latest version”

occ cannot upgrade to new major version

according to https://help.nextcloud.com/t/web-console-shows-upgrade-available-but-occ-says-latest-already-installed/88439/2 and https://docs.nextcloud.com/server/16/admin_manual/maintenance/update.html#using-the-command-line-based-updater you should run something like:

sudo -u www-data php updater.phar

Add Redis Caching

Install Redis:

apt-get install redis

Add to config/config.php to use Redis cache everywhere:

  'memcache.local' => '\OC\Memcache\Redis',
  'memcache.distributed' => '\OC\Memcache\Redis',
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => [
    'host' => 'localhost',
    'port' => 6379,
  ],

Telephone Warning

Add to config/config.php:

'default_phone_region' => 'SK',

Required PHP Dependendencies

apt-get install php8.2-mysql php8.2-redis php8.2-xml php8.2-zip php8.2-mbstring php8.2-gd php8.2-curl php8.2-intl php8.2-gmp php8.2-bcmath

Missing php-mysql:

root@starz:/home/phpservices/nextcloud# php7.4 occ --help
An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /home/phpservices/nextcloud/lib/private/DB/Connection.php:139
Stack trace:
#0 /home/phpservices/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /home/phpservices/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /home/phpservices/nextcloud/lib/private/DB/Connection.php(261): Doctrine\DBAL\Connection->executeQuery()
#3 /home/phpservices/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /home/phpservices/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /home/phpservices/nextcloud/lib/private/AppConfig.php(419): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /home/phpservices/nextcloud/lib/private/AppConfig.php(184): OC\AppConfig->loadConfigValues()
#7 /home/phpservices/nextcloud/lib/private/AppConfig.php(375): OC\AppConfig->getApps()
#8 /home/phpservices/nextcloud/lib/private/legacy/OC_App.php(967): OC\AppConfig->getValues()
#9 /home/phpservices/nextcloud/lib/private/Server.php(725): OC_App::getAppVersions()
#10 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\Server->OC\{closure}()
#11 /home/phpservices/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(130): Pimple\Container->offsetGet()
#13 /home/phpservices/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#14 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#15 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(185): OC\AppFramework\Utility\SimpleContainer->get()
#16 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /home/phpservices/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(130): Pimple\Container->offsetGet()
#19 /home/phpservices/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#20 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#21 /home/phpservices/nextcloud/lib/private/Server.php(1121): OC\AppFramework\Utility\SimpleContainer->get()
#22 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\Server->OC\{closure}()
#23 /home/phpservices/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(130): Pimple\Container->offsetGet()
#25 /home/phpservices/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#26 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#27 /home/phpservices/nextcloud/lib/private/Server.php(2072): OC\AppFramework\Utility\SimpleContainer->get()
#28 /home/phpservices/nextcloud/lib/private/Files/View.php(117): OC\Server->getLockingProvider()
#29 /home/phpservices/nextcloud/lib/private/Server.php(462): OC\Files\View->__construct()
#30 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(163): OC\Server->OC\{closure}()
#31 /home/phpservices/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(130): Pimple\Container->offsetGet()
#33 /home/phpservices/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#34 /home/phpservices/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#35 /home/phpservices/nextcloud/lib/private/Server.php(1474): OC\AppFramework\Utility\SimpleContainer->get()
#36 /home/phpservices/nextcloud/lib/base.php(617): OC\Server->boot()
#37 /home/phpservices/nextcloud/lib/base.php(1145): OC::init()
#38 /home/phpservices/nextcloud/console.php(48): require_once('/home/phpservic...')
#39 /home/phpservices/nextcloud/occ(11): require_once('/home/phpservic...')
#40 {main}

Missing php-redis:

root@starz:/home/phpservices/nextcloud# php7.4 occ --help
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\Redis not available for distributed cache (Is the matching PHP module installed and enabled?)

Missing php-xml:

root@starz:/home/phpservices/nextcloud# php7.4 occ --help
An unhandled exception has been thrown:
Error: Call to undefined function simplexml_load_file() in /home/phpservices/nextcloud/lib/private/App/InfoParser.php:66
Stack trace:
#0 /home/phpservices/nextcloud/lib/private/App/AppManager.php(507): OC\App\InfoParser->parse()
#1 /home/phpservices/nextcloud/lib/private/legacy/OC_App.php(598): OC\App\AppManager->getAppInfo()
#2 /home/phpservices/nextcloud/lib/private/AppFramework/App.php(74): OC_App::getAppInfo()
#3 /home/phpservices/nextcloud/lib/private/legacy/OC_App.php(281): OC\AppFramework\App::buildAppNamespace()
#4 /home/phpservices/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php(117): OC_App::registerAutoloading()
#5 /home/phpservices/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php(91): OC\AppFramework\Bootstrap\Coordinator->registerApps()
#6 /home/phpservices/nextcloud/lib/base.php(671): OC\AppFramework\Bootstrap\Coordinator->runInitialRegistration()
#7 /home/phpservices/nextcloud/lib/base.php(1145): OC::init()
#8 /home/phpservices/nextcloud/console.php(48): require_once('/home/phpservic...')
#9 /home/phpservices/nextcloud/occ(11): require_once('/home/phpservic...')

Missing php-zip, php-mbstring, php-gd, php-curl:

www-data@starz:/home/phpservices/nextcloud$ php7.4 occ --help
PHP module zip not installed.
Please ask your server administrator to install the module.

PHP module mbstring not installed.
Please ask your server administrator to install the module.

PHP module GD not installed.
Please ask your server administrator to install the module.

PHP module cURL not installed.
Please ask your server administrator to install the module.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /home/phpservices/nextcloud/lib/private/Console/Application.php:166
Stack trace:
#0 /home/phpservices/nextcloud/console.php(99): OC\Console\Application->loadCommands()
#1 /home/phpservices/nextcloud/occ(11): require_once('/home/phpservic...')
#2 {main}

Missing php-intl:

www-data@starz:/home/phpservices/nextcloud$ php occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Turned on maintenance mode
Updating database schema
Updated database
Updating <bookmarks> ...
Exception: App "Bookmarks" cannot be installed because the following dependencies are not fulfilled: The library intl is not available.
Update failed
Maintenance mode is kept active
Resetting log level

“This version of Nextcloud is not compatible with PHP>=8.2”

This version of Nextcloud is not compatible with PHP>=8.2.
You are currently running 8.2.7.

v25 is not compatible, but v26 is, manual upgrade is needed, because CLI scripts don’t work either

PHP 5

php5 occ --help
PHP Warning:  Unsupported declare 'strict_types' in /home/phpservices/nextcloud/lib/versioncheck.php on line 3
This version of Nextcloud requires at least PHP 7.4<br/>You are currently running 5.6.33-0+deb8u1. Please update your PHP version.

Tried with PHP 5 I still had….

“Console has to be executed with the user that owns the file config/config.php”

root@starz:/home/phpservices/nextcloud# php7.4 occ --help
Console has to be executed with the user that owns the file config/config.php
Current user id: 0
Owner id of config.php: 33
Try adding 'sudo -u #33' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u 33' to the docker command (without the single quotes)

You need to switch to www-data or user which owns config/config.php:

  • sudo -u www-data php occ --help
  • sudo su -l www-data -s /bin/bash and run commands

“This account is currently not available”

su - www-data php7.4 occ 
This account is currently not available.

You need to specify also shell, see the point above.

occ Show Version

www-data@starz:/home/phpservices/nextcloud$ php7.4 occ --version
MyrtanaVOblakoch 25.0.7

occ Show Configuration

php occ config:list

“Updates between multiple major versions and downgrades are unsupported”

Update to 27.0.0

Exception: Updates between multiple major versions and downgrades are unsupported.
Detailed logs

Preparing update

Set log level to debug

Turned on maintenance mode

Exception: Updates between multiple major versions and downgrades are unsupported.

The update was unsuccessful. For more information check our forum post covering this issue.

Skipping major version is not supported, e.g. 25 -> 27. The correct upgrade path is 25 -> 26 -> 27.

Copy Stuff From Old Nextcloud

Copy config files, plugins you use and set permissions. I copied only two plugins, I don’t care that much about others. In the end others are still enabled even if I haven’t copied them, not sure what is the difference.

cp nextcloud_old/config/config.php nextcloud/config/
cp -r nextcloud_old/apps/bookmarks nextcloud/apps/
cp -r nextcloud_old/apps/notes nextcloud/apps/

chown -R www-data:www-data nextcloud
find nextcloud/ -type d -exec chmod 750 {} \;
find nextcloud/ -type f -exec chmod 640 {} \;

Issues With Github Release

www-data@starz:/home/phpservices/nextcloud$ php occ upgrade
Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".

Shame there are no .git directories, you need to clone or download from https://nextcloud.com/changelog.

www-data@starz:/home/phpservices/nextcloud$ cd 3rdparty/
www-data@starz:/home/phpservices/nextcloud/3rdparty$ git submodule update --init
fatal: not a git repository (or any of the parent directories): .git

“Nextcloud or one of the apps require upgrade - only a limited number of commands are available”

Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade

Run php occ upgrade.

Turn Off Maintenance Mode

www-data@starz:/home/phpservices/nextcloud$ php occ maintenance:mode
Maintenance mode is currently enabled
www-data@starz:/home/phpservices/nextcloud$ php occ maintenance:mode --off

Successful Upgrade

www-data@starz:/home/phpservices/nextcloud$ php occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Turned on maintenance mode
Updating database schema
Updated database
Disabled incompatible app: calendar
Disabled incompatible app: contacts
Disabled incompatible app: mail
Disabled incompatible app: onlyoffice
Disabled incompatible app: richdocuments
Disabled incompatible app: spreed
Updating <lookup_server_connector> ...
Updated <lookup_server_connector> to 1.14.0
Updating <oauth2> ...
Updated <oauth2> to 1.14.0
Updating <password_policy> ...
Updated <password_policy> to 1.16.0
Updating <photos> ...
Updated <photos> to 2.2.0
Updating <files> ...
Updated <files> to 1.21.1
Updating <activity> ...
Updated <activity> to 2.18.0
Updating <circles> ...
Updated <circles> to 26.0.0
Updating <cloud_federation_api> ...
Updated <cloud_federation_api> to 1.9.0
Updating <dav> ...
Fix broken values of calendar objects

 Done
    0/0 [->--------------------------]   0%
Clean up old calendar subscriptions from deleted users that were not cleaned-up
 Done
    0/0 [----->----------------------]   0%
Updated <dav> to 1.25.0
Updating <files_sharing> ...
Updated <files_sharing> to 1.18.0
Updating <files_trashbin> ...
Updated <files_trashbin> to 1.16.0
Updating <files_versions> ...
Updated <files_versions> to 1.19.1
Updating <sharebymail> ...
Updated <sharebymail> to 1.16.0
Updating <workflowengine> ...
Updated <workflowengine> to 2.8.0
Updating <comments> ...
Updated <comments> to 1.16.0
Updating <firstrunwizard> ...
Updated <firstrunwizard> to 2.15.0
Updating <nextcloud_announcements> ...
Updated <nextcloud_announcements> to 1.15.0
Updating <notifications> ...
Updated <notifications> to 2.14.0
Updating <systemtags> ...
Updated <systemtags> to 1.16.0
Updating <theming> ...
Migrate old user accessibility config
 Done
    1/1 [============================] 100%
Updated <theming> to 2.1.1
Updating <bruteforcesettings> ...
Updated <bruteforcesettings> to 2.6.0
Updating <contactsinteraction> ...
Updated <contactsinteraction> to 1.7.0
Updating <dashboard> ...
Updated <dashboard> to 7.6.0
Updating <federatedfilesharing> ...
Updated <federatedfilesharing> to 1.16.0
Updating <files_pdfviewer> ...
Updated <files_pdfviewer> to 2.7.0
Updating <files_rightclick> ...
Updated <files_rightclick> to 1.5.0
Updating <logreader> ...
Updated <logreader> to 2.11.0
Updating <privacy> ...
Updated <privacy> to 1.10.0
Updating <provisioning_api> ...
Updated <provisioning_api> to 1.16.0
Updating <recommendations> ...
Updated <recommendations> to 1.5.0
Updating <related_resources> ...
Updated <related_resources> to 1.1.0-alpha1
Updating <serverinfo> ...
Updated <serverinfo> to 1.16.0
Updating <settings> ...
Updated <settings> to 1.8.0
Updating <support> ...
Updated <support> to 1.9.0
Updating <survey_client> ...
Updated <survey_client> to 1.14.0
Updating <text> ...
Updated <text> to 3.7.2
Updating <twofactor_backupcodes> ...
Updated <twofactor_backupcodes> to 1.15.0
Updating <updatenotification> ...
Updated <updatenotification> to 1.16.0
Updating <user_status> ...
Updated <user_status> to 1.6.0
Updating <viewer> ...
Updated <viewer> to 1.10.0
Updating <weather_status> ...
Updated <weather_status> to 1.6.0
Update app bookmarks from App Store
Update app notes from App Store
Restore default tags that are missing
 Done
    0/0 [------------->--------------]   0%
Purify and migrate collected mail addresses
 Done
    0/0 [---------------->-----------]   0%
Insert background jobs for all accounts
 Done
    0/0 [-------------------->-------]   0%
Starting code integrity check...
Finished code integrity check
Update successful
Turned off maintenance mode
Resetting log level
www-data@starz:/home/phpservices/nextcloud$

References:

Add Comment