How to Safely Update Your Nextcloud Server via Web Updater and CLI

What is Nextcloud and why are updates important?

Nextcloud is a self hosted cloud platform for files, calendars, contacts, notes, tasks and much more. You can run Nextcloud on your own server, in a VM, inside an LXC container or at a hosting provider and keep full control over your data.

Regular Nextcloud updates are important because they

  • close security holes
  • add new features and improvements
  • fix bugs and incompatibilities
  • keep your setup compatible with current PHP versions and databases

In this guide I show you how to update your Nextcloud server, which commands you should know and when it is better to use the Web Updater or the command line.

Preparation – backup before every Nextcloud server update

Before you update your Nextcloud server you should always have a current backup. An update that fails halfway is rare, but it can break your installation. With a backup you are on the safe side.

Possible backup options

nextcloud-update-01-proxmox

nextcloud-update-01-proxmox

nextcloud-update-02-proxmox

nextcloud-update-02-proxmox

nextcloud-update-03-proxmox

nextcloud-update-03-proxmox

nextcloud-update-04-proxmox

nextcloud-update-04-proxmox

nextcloud-update-05-proxmox

nextcloud-update-05-proxmox

  • Snapshot of the VM or LXC container in your hypervisor, for example Proxmox
  • Full backup of the container or VM
  • Manual backup of:
    • Nextcloud installation directory, for example /var/www/html or /var/www/nextcloud
    • data directory (data or an external storage / NAS)
    • database (MariaDB, MySQL or PostgreSQL)

A simple MySQL or MariaDB backup could look like this:

mysqldump -u nextcloud -p nextcloud > /root/nextcloud.sql

If you are using Proxmox, a snapshot or full backup of the container before every Nextcloud server update is usually the most convenient option.

Updating Nextcloud via Web Updater

The Web Updater is the easiest way to update your Nextcloud server. You only need a browser and admin access to Nextcloud.

Step by step – Web Updater

nextcloud-update-06

nextcloud-update-06

nextcloud-update-07

nextcloud-update-07

nextcloud-update-08

nextcloud-update-08

nextcloud-update-09

nextcloud-update-09

nextcloud-update-10

nextcloud-update-10

  1. Log in to Nextcloud as admin user.
  2. In the left sidebar go to Administration and then Overview.
  3. If a new version is available you will see a notice. Click the Open updater button.
  4. The Web Updater opens and shows a list of the planned steps.
  5. Click Start update.
  6. The updater downloads the new version, checks the files, creates a backup and installs the new version.
  7. At the end you will see a button like Disable maintenance mode and continue in the web based updater. Click it to disable maintenance mode.
  8. Log in to Nextcloud again and check if everything works.
  9. Open the Apps section and install all available app updates.

The Web Updater is ideal for small private installations with only a few users and a manageable amount of data. On large instances you might run into PHP timeouts or slow disks – in this case the CLI is usually more reliable.

Updating Nextcloud via CLI (Command Line Updater and occ)

Updating your Nextcloud server from the command line is a bit more technical, but much more robust and better suited for larger installations.

1. Change to the Nextcloud directory

In most setups the installation is located under /var/www/html or /var/www/nextcloud:

cd /var/www/html

Adjust the path to your environment.

2. Start the CLI Updater

On Debian or Ubuntu the web server usually runs as www-data. With the following command you start the updater on the CLI:

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

If you want to skip the internal backup of the updater because you already created a snapshot in your hypervisor, you can use the --no-backup option:

sudo -E -u www-data php updater/updater.phar --no-backup

The updater asks if you want to run the Nextcloud server update, downloads the new version, verifies it and replaces the files. At the end it usually suggests running the occ upgrade command.

3. Update the database

After the files have been replaced the database has to be upgraded to the new version. This is done with occ upgrade:

sudo -E -u www-data php --define apc.enable_cli=1 occ upgrade

The apc.enable_cli=1 option enables APCu caching for CLI commands which speeds up some operations.

4. Disable maintenance mode

If Nextcloud is still in maintenance mode after the update you can switch it off like this:

sudo -E -u www-data php --define apc.enable_cli=1 occ maintenance:mode --off

After that you should be able to log in to the web interface again.

5. Clean up database and storage

After major updates it is a good idea to do a bit of cleanup:

# add missing indices
sudo -E -u www-data php --define apc.enable_cli=1 occ db:add-missing-indices

# clean up trashbin and file versions for a user, example user "cosci"
sudo -u www-data php --define apc.enable_cli=1 occ trashbin:cleanup cosci
sudo -u www-data php --define apc.enable_cli=1 occ versions:cleanup cosci

You can also update all apps directly via CLI:

sudo -E -u www-data php occ app:update --all

Web Updater or CLI – which option should you use?

Both methods technically update your Nextcloud server in the same way. Still there are differences that help you to decide which method to use.

Comparison – Web Updater vs CLI

MethodAdvantagesDisadvantagesRecommendation
Web Updatervery simple, all in the browser, no shell knowledge neededprone to PHP timeouts, less detailed error messagesgood for small private installations
CLI with updater.pharstable, fast, easy to script, clear log outputrequires SSH access and basic shell knowledgerecommended for production and larger setups
manual updatefull control over files and workflowmore complex, easier to make mistakesonly if the updater does not work at all

For homelab setups, company clouds or Nextcloud servers with many users the CLI update is usually much less stressful. For a small private Nextcloud the Web Updater is often enough.

Updating the PHP version for your Nextcloud server

Sooner or later you will not only run a Nextcloud server update but also a PHP upgrade. Which PHP version is supported depends on your Nextcloud version. Before you change the PHP version always check in the admin overview which version is recommended.

In general:

  • a current PHP 8.x version is usually a good choice
  • older PHP versions will eventually lose support
  • new PHP versions should only be used once they are officially supported by Nextcloud

A typical switch from PHP 8.3 to PHP 8.4 on an Ubuntu server with Apache could look like this:

sudo apt update
sudo apt upgrade -y

sudo apt install -y \
  php8.4-cli php8.4-common php8.4-curl php8.4-gd php8.4-mbstring \
  php8.4-xml php8.4-zip php8.4-intl php8.4-bcmath php8.4-gmp \
  php8.4-apcu php8.4-redis php8.4-imagick \
  php8.4-mysql

sudo apt install -y libapache2-mod-php8.4

sudo a2dismod php8.3
sudo a2enmod php8.4
sudo systemctl restart apache2

sudo update-alternatives --set php /usr/bin/php8.4

sudo -u www-data php8.4 /var/www/html/occ status

The last command checks if your Nextcloud server is running correctly with the new PHP version.

Important occ commands for Nextcloud server updates

Here is a small overview of practical occ commands that are useful around every Nextcloud server update:

CommandPurpose
sudo -E -u www-data php occ statusshows version, installation status and paths
sudo -E -u www-data php occ update:checkchecks for new Nextcloud versions and app updates
sudo -E -u www-data php occ upgraderuns database migrations for the new version
sudo -E -u www-data php occ maintenance:mode --on/--offenables or disables maintenance mode
sudo -E -u www-data php occ db:add-missing-indicescreates missing database indices
sudo -E -u www-data php occ app:update --allupdates all apps
sudo -E -u www-data php occ trashbin:cleanup <user>cleans up the trashbin of a specific user
sudo -E -u www-data php occ versions:cleanup <user>removes old file versions of a specific user

By combining backups, the right update method and these occ commands you can keep your Nextcloud server secure, up to date and ready for new features without unnecessary downtime.

Durchschnittliche Bewertung 0 / 5. Bewertungen: 0

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top