2 Ways to Upgrade Nextcloud [Command-Line & GUI]

It’s important to keep your Nextcloud server up to date with the latest security and bug fixes. This tutorial is going to show you how to upgrade NextCloud using the updater app, which automates many steps of a manual upgrade.

2 Ways to Upgrade Nextcloud [Command-Line & GUI]

Prerequisites

You should have a Nextcloud instance up and running. If not, please follow one of the tutorials below to set up your Nextcloud server.

Backing Up your Nextcloud

Before updating Nextcloud, you should back up the NextCloud database and configuration file.

Backing Up NextCloud Database

To backup NextCloud database, first you need to find out the database name by running the following command on your NextCloud server.

sudo mysql -u root -e "show databases"

If your MariaDB requires password authentication, then run this command instead. Enter the password of MariaDB/MySQL root user.

mysql -u root -p -e "show databases"

You will see something like below:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud          |
| performance_schema |
+--------------------+

As you can see, my NextCloud database name is nextcloud. Once you have identified the NextCloud database name, use mysqldump utility to make a backup like below. Replace red text with your own NextCloud database name.

sudo mysqldump -u root nextcloud-database-name > ~/nextcloud.sql

or

mysqldump -u root -p nextcloud-database-name > ~/nextcloud.sql

The above command creates a dump file (nextcloud.sql) under your home directory and it can be used to restore Nextcloud database if any disastrous things happen.

Backing Up NextCloud Config Folder

To back up NextCloud config folder, first cd into Nextcloud installation directory. (Depending on your setup, your Nextcloud installation directory may be different. For example, If you set up Nextcloud with LAMP stack, the directory might be /var/www/nextcloud/. If you set up Nextcloud with LEMP stack, the data directory might be /usr/share/nginx/nextcloud/).

cd /var/www/nextcloud/

Then use tar to back up the config folder.

sudo tar -cpzvf ~/nextcloud-config.tar.gz config/

Because config.php file is read only by web server, so we have to add sudo. The backup file (nextcloud-config.tart.gz) will be placed under your home directory.

Now let’s upgrade NextCloud.

Note: You must upgrade to the latest point release before upgrading to the next major release.

Upgrade Nextcloud From the Command Line

The command-line method is more efficient and you will see less errors compared to the web-based updater app. If your Nextcloud instance has lots of users and files, you should use the command-line method.

Go to the NextCloud installation directory. (Depending on your setup, your Nextcloud installation directory may be different. For example, If you set up Nextcloud with LAMP stack, the directory might be /var/www/nextcloud/. If you set up Nextcloud with LEMP stack, the data directory might be /usr/share/nginx/nextcloud/).

cd /var/www/nextcloud/

Then run launch the command-line based updater.

sudo -u www-data php7.4 updater/updater.phar --no-interaction

www-data is the username of web server, which may be different on your system.

  • On Debian/Ubuntu, it’s usually www-data,
  • On CentOS/RHEL, it’s usually apache for Apache web server and nginx for Nginx web server.
  • On Arch Linux, it’s usually http.

Upgrade Nextcloud From the Command Line

Once the upgrade is complete, go to the Settings -> Overview page and you shall see your Nextcloud version is up to date.

Note: Don’t forget to re-enable third-party apps after the upgrade.

You can create a Cron job, so Nextcloud can be upgraded automatically. Edit the www-data user’s crontab file.

sudo -u www-data crontab -e

Add the following line to the end of this file. Obviously, you need to replace /var/www/nextcloud/ with your own Nextcloud installation directory.

0 3 * * * php7.4 /var/www/nextcloud/updater/updater.phar --no-interaction

Save and close the file. The Cron job will run at 3 AM each day.

Troubleshooting Tip: Sometimes an upgrade can fail due to PHP incompatibility. You can try to upgrade to a new PHP version such as PHP7.4 -> PHP8.0, then run the upgrade command again.

Upgrade NextCloud with the Graphical Web-based Updater App

Go to the NextCloud Settings page, and select the Overview tab on the left sidebar. If a new version is available, then click the Open updater button.

Upgrade NextCloud with the Graphical Web-based Updater App

Then click the start update button.

nextcloud upgrade

NextCloud will be put into maintenance mode and prepare itself for upgrade. If you encounter an error, please check the troubleshooting tips in the later part of this article.

upgrade nextcloud

Once this step is complete, you have the option to keep maintenance active or disable maintenance mode.

  • If you have a large NextCloud installation (many users and files), then it’s recommended to select Yes and use command line to update NextCloud.
  • If you have a small NextCloud installation, you can choose No and use the web-based updater.

nextcloud maintenance mode

If you choose No, then click Go back to your Nextcloud intance to finish the update button. You will be redirected to NextCloud home page and presented with the following screen. Click Start Update.

nextcloud update

The update time varies depending on your installation size. In my case, it finished in a few seconds. Once the update is complete, go to the Settings -> Overview page and you shall see your Nextcloud version is up to date.

If you choose Yes in the previous step, then you need to go into NextCloud installation directory and issue a command to start the upgrade. (Depending on your setup, your Nextcloud installation directory may be different. For example, If you set up Nextcloud with LAMP stack, the directory might be /var/www/nextcloud/. If you set up Nextcloud with LEMP stack, the data directory might be /usr/share/nginx/nextcloud/).

cd /usr/share/nginx/nextcloud/

sudo -u www-data php7.4 occ upgrade

www-data is the username of web server, which may be different on your system.

  • On Debian/Ubuntu, it’s usually www-data,
  • On CentOS/RHEL, it’s usually apache for Apache web server and nginx for Nginx web server.
  • On Arch Linux, it’s usually http.

Once the upgrade is complete, disable maintenance mode with:

sudo -u www-data php7.4 occ maintenance:mode --off

Go to the Settings -> Overview page and you shall see your Nextcloud version is up to date.

Note: Don’t forget to re-enable third party apps after upgrade.

Troubleshooting Tips

Extra Files

When upgrading Nextcloud, you may see this error:

The following extra files have been found:

.well-know

You can backup these “extra” files, delete them and retry update. Once the update is finished, put these files back.

504 Gateway Timeout

If the download failed because of 504 gateway timeout error, then you need to restart PHP-FPM.

sudo systemctl restart php7.4-fpm

Failure to Download Nextcloud ZIP File

If you encounter the following error, this is likely because your server failed to download the new Nextcloud ZIP file.

Step 4 is currently in process. Please reload this page later.

You need to SSH into your Nextcloud server, and switch to the root user.

sudo su -

Go to your Nextcloud data directory. (Depending on your setup, your data directory may be different. For example, If you set up Nextcloud with LAMP stack, the data directory might be /var/www/nextcloud-data/. If you set up Nextcloud with LEMP stack, the data directory might be /usr/share/nginx/nextcloud-data/).

cd /usr/share/nginx/nextcloud-data/

In this directory, there’s a sub-directory that begins with updater. You can run ls command to list the files and sub-directories.

ls

Mine is named updater-ocao79wqklov, so I change to this sub-directory.

cd updater-ocao79wqklov

Then list all files and sub-directories, including the hidden ones.

ls -a

You will find a .step file and a downloads sub-directory. The .step file keeps track of the upgrade status. We need to delete this file.

rm .step

Then go to the downloads sub-directory.

cd downloads/

Remove the downloaded ZIP file.

rm nextcloud-*.zip

Then we manually download the Nextcloud ZIP file with the following command. Obviously you need to replace 20.0.8 with the Nextcloud version you want to upgrade to.

wget https://download.nextcloud.com/server/releases/nextcloud-20.0.8.zip

Once the download is complete, go back to the web-based updater app and click the start update button.

Repair your Nextcloud Installation

If you can’t fix an error using the above tips, you can use the Nextcloud repair command. Go to your Nextcloud installation directory and run the following command.

sudo -u www-data php7.4 occ maintenance:repair

Unable to Upgrade to the Next Major Release?

A major stable release can take some time to be included in the stable update channel, because there might be some apps that don’t have updates for the next major stable release.

For example, Nextcloud 21 is now the latest stable version, but the the web-based updater app doesn’t allow you to upgrade to Nextcloud 21. In this case, you need to change the update channel from stable to beta.

nextcloud change the update channel from stable to beta

Then you can upgrade to Nextcloud 21, with the caveat that some apps won’t be usable.

A new version is available Nextcloud 21

After the upgrade is complete, I recommend changing back to the stable update channel.

Running Nextcloud 21 with PHP8

Nextcloud fully supports PHP8 starting with version 21. First, install PHP8 on your Ubuntu server with:

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php-imagick libapache2-mod-php8.0 php8.0-common php8.0-mysql php8.0-fpm php8.0-gd php8.0-curl php8.0-zip php8.0-xml php8.0-mbstring php8.0-bz2 php8.0-intl php8.0-bcmath php8.0-gmp

Then read the following tutorial to change your Apache/Nginx virtual host to use PHP8.0.

To check if your Nextcloud is using PHP 8, go to the Nextcloud Settings -> System page.

After upgrading to PHP 8, your Nextcloud instance might complain that

The PHP memory limit is below the recommended value of 512MB.

Run the following command to change the memory limit in PHP8.

sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/8.0/fpm/php.ini

Then reload PHP-FPM service for the changes to take effect.

sudo systemctl reload php8.0-fpm

Wrapping Up

I hope this tutorial helped you upgrade Nextcloud. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 14 Average: 4.3]

2 Responses to “2 Ways to Upgrade Nextcloud [Command-Line & GUI]

  • Hi,

    Thank you for the instructions , it is very easy to follow. You were my last hope because I have been stuck for several weeks now with this error: Step 5 is currently in process. Please reload this page later.

    I do not have the .step file in my nextcloud folder so I cannot get rid of this step , I have tried everything I could find on the forums but still stuck. Do you have any idea on how to fix this?

    Thank you

  • never mind, I found a solution: sudo -u www-data php /var/www/html/nextcloud/occ maintenance:repair

    then I ran your command line and done!

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.