Nextcloud update using cli only

Nextcloud X → Nextcloud Y


Last Updates:

March, 01st 2019:
– link to shell scripts


Nextcloud can be updated using the Nextcloud command line interface only. Even your enabled apps will be updated as far as they are available on the Nextcloud app store. First backup your Nextcloud system (database and data). Then keep it simple – download all as a shell script for NGINX based environments

Ubuntu 18.04.x Bionic Beaver:

sudo -s
wget https://raw.githubusercontent.com/criegerde/install-nextcloud/master/maintenance/ubuntu/upgrade-ubuntu.sh
chmod +x upgrade-ubuntu.sh && ./upgrade-ubuntu.sh

Debian 9.x Stretch:

sudo -s
wget https://raw.githubusercontent.com/criegerde/install-nextcloud/master/maintenance/debian/upgrade-debian.sh
chmod +x upgrade-debian.sh && ./upgrade-debian.sh

or perform the upgrade manually:

sudo -s
cd /var/www/nextcloud
/usr/sbin/service nginx stop

or on APACHE2 environments

sudo -s
cd /var/www/html/nextcloud
/usr/sbin/service apache2 stop

Start the update

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

Press y to start updating your Nextcloud and y again to continue

Now the code was updated. Press n to disable Nextclouds maintenance mode and the update has ben finished already.

You are on the latest Nextcloud release – it can be verifed by

sudo -u www-data php occ status
sudo -u www-data php occ -V

On NGINX environments modify Nextclouds .user.ini

sudo -u www-data sed -i "s/upload_max_filesize=.*/upload_max_filesize=10240M/" /var/www/nextcloud/.user.ini
sudo -u www-data sed -i "s/post_max_size=.*/post_max_size=10240M/" /var/www/nextcloud/.user.ini
sudo -u www-data sed -i "s/output_buffering=.*/output_buffering='Off'/" /var/www/nextcloud/.user.ini

or on Apache2 environments modify Nextclouds (.htaccess) as described here

...
<IfModule mod_php7.c>
php_value upload_max_filesize 10240M
php_value post_max_size 10240M
php_value memory_limit 512M
php_value mbstring.func_overload 0
php_value default_charset 'UTF-8'
php_value output_buffering 'Off'
<IfModule mod_env.c>
...
ErrorDocument 403 /
ErrorDocument 404 /
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]
RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]
RewriteCond %{REQUEST_FILENAME} !\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg)$
RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$
RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$
RewriteCond %{REQUEST_FILENAME} !/remote.php
RewriteCond %{REQUEST_FILENAME} !/public.php
RewriteCond %{REQUEST_FILENAME} !/cron.php
RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php
RewriteCond %{REQUEST_FILENAME} !/status.php
RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php
RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php
RewriteCond %{REQUEST_FILENAME} !/robots.txt
RewriteCond %{REQUEST_FILENAME} !/updater/
RewriteCond %{REQUEST_FILENAME} !/ocs-provider/
RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
RewriteRule . index.php [PT,E=PATH_INFO:$1]
RewriteBase /
<IfModule mod_env.c>
SetEnv front_controller_active true
<IfModule mod_dir.c>
DirectorySlash off
</IfModule>
</IfModule>
</IfModule>

Verify all indices are properly set and everything ist up to date:

sudo -u www-data php occ db:add-missing-indices
sudo -u www-data php occ db:convert-filecache-bigint
sudo -u www-data php occ update:check

Restart both, PHP and NGINX

/usr/sbin/service php7.3-fpm restart
/usr/sbin/service nginx restart

or PHP and APACHE2

/usr/sbin/service php7.3-fpm restart
/usr/sbin/service apache2 restart

If app updates are found just issue

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

or

sudo -u www-data php occ app:update <app-name>

sudo -u www-data php occ app:update contacts

Done!


Enjoy your personal data in your secured and hardened Nextcloud-Server!

Don’t forget to backup your Nextcloud

Find more instructions here: Nextcloud backup and restore



Carsten Rieger

Carsten Rieger

Carsten Rieger is a senior system engineer in full-time and also working as an IT freelancer. He is working with linux environments for more than 13 years, an Open Source enthusiast and highly motivated on linux installation and troubleshooting. Mostly working with Debian/Ubuntu Linux, Nginx and Apache web server, MariaDB/MySQL/PostgreSQL, PHP, Cloud infrastructure (e.g. Nextcloud) and other open source projects (e.g. Roundcube) and in voluntary work for the Dr. Michael & Angela Jacobi Stiftung for more than 7 years.

17 Responses

  1. Felix says:

    Hallo Carsten,

    auch ich möchte gerne mein Nextcloud updaten, bekomme aber nach dem ausführen des “chmod +x upgrade-ubuntu.sh && ./upgrade-ubuntu.sh” diese Meldung.

    An unhandled exception has been thrown:
    Error: Class ‘OC\Core\Command\Db\AddMissingIndices’ not found in /var/www/nextcloud/core/register_command.php:93
    Stack trace:
    #0 /var/www/nextcloud/lib/private/Console/Application.php(118): require_once()
    #1 /var/www/nextcloud/console.php(95): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #2 /var/www/nextcloud/occ(11): require_once(‘/var/www/nextcl…’)
    #3 {main}PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYroot@ubuntu-Nextcloud:/var/wTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY^C

    (o: Hast du eine Idee?

    Danke.

    • Welche Nextcloud Version betreibst Du? Welchen ouput erhälst Du bei diesem Befehl:
      sudo -u www-data php /var/www/nextcloud/occ -V

      • Felix says:

        Danke für die Rückmeldung. Ich erhalte diese Meldung.

        An unhandled exception has been thrown:
        Error: Class ‘OC\Core\Command\Db\AddMissingIndices’ not found in /var/www/nextcloud/core/register_command.php:93
        Stack trace:
        #0 /var/www/nextcloud/lib/private/Console/Application.php(118): require_once()
        #1 /var/www/nextcloud/console.php(95): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
        #2 /var/www/nextcloud/occ(11): require_once(‘/var/www/nextcl…’)
        #3 {main}PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYspooky@ubuntu-Nextcloud:~$ PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTTYPuTTYPuTTYPuTTYPuTTYPuTTY

        • Felix says:

          Version ist 15.0.4

        • Versuche mal das: sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices && sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint
          Funktioniert das? Kann ich evtl. per SSH mal direkt auf den Server?

          • Felix says:

            Sehr gerne kannst du da einmal drauf gucken. Wie gebe ich dir den Zugang?
            Ich erhalte immer diese Meldung…

            An unhandled exception has been thrown:
            Error: Class ‘OC\Core\Command\Db\AddMissingIndices’ not found in /var/www/nextcloud/core/register_command.php:93
            Stack trace:
            #0 /var/www/nextcloud/lib/private/Console/Application.php(118): require_once()
            #1 /var/www/nextcloud/console.php(95): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
            #2 /var/www/nextcloud/occ(11): require_once(‘/var/www/nextcl…’)
            #3 {main}PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYroot@ubuntu-Nextcloud:~# PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPPuTTYPuTTYPuTTYPuTTYPuTTY^C

  2. Christof says:

    Moin von der Küste!

    In Deinen Update-Scripts ist im nachfolgenden chmod ein kleiner Fehler drin (Ubuntu & Debian):

    chmod +x upgrade-on-debian.sh && ./upgrade-on-debian.sh

    Müsste lauten (da Dein Script auf GitHub ohne das “on” benannt ist):

    chmod +x upgrade-debian.sh && ./upgrade-debian.sh

    Ansonsten wie immer erste Sahne!

    LG & schönes WE!

    Christof

  3. Carlos says:

    Hi Carsten,

    I find that my system is running php7.2 instead of php7.3. Is that a big problem for the performance of nextcloud? What is the best way to update php while ensuring nextcloud continues to work properly?

    As always, excellent job with these tutorials. Keep up the great work!

    Best,
    Carlos

    • You don’t have to update (no need) but you could. Install php7.3 as written in the guide.
      If you’re done stop nginx and stop and disable php7.2. Then change the php handler in nginx.conf and enable/start 7.3. That’s all 😉

  4. Marco says:

    Hi,

    ich habe dein Script für die Nextcloud Installation benutzt, danke dafür.
    Allerdings habe ich nun folgende Fehlermeldung wenn ich von Version 14.0.3 auf Version 14.0.4 aktualisieren möchte.

    ***
    Could not copy “/var/www/nextcloud/config/config.php.orig” to “/var/nc_data/updater-oc751ztl6eab/backups/nextcloud-14.0.3.0/config/config.php.orig”. Source /var/www/nextcloud/config/config.php.orig is not readable. Destination /var/nc_data/updater-oc751ztl6eab/backups/nextcloud-14.0.3.0/config/config.php.orig is not writable
    ***

    Kannst du mir sagen wie ich das beheben kann?

    Besten Dank.

  5. Manni says:

    .. wieder mal eine geniale meisterliche Anleitung. :o))))))

    Wenn man sich an die Anleitungen hält, klappt das mit dem Nachbar, ähh Nextcloud.

Leave a Reply

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