Server migration issues

I’m in the middle of a big overhaul of our Nextcloud instance. I had Nextcloud running on an older version of Debian which only supported up to php 5.6, which prevented me from upgrading my copy of Nextcloud beyond version 13. Well, Linux upgrades suck so I transitioned it to FreeBSD and inside a jail. I’ve done this before so I know the steps. But it seems Nextcloud has encountered an issue.

I backed up the database with a dump and restored it, ran mysql_upgrade since this has gone from mariadb 10.1 to 10.3, and it has gone from apache2 to nginx and php 7.1. FreeBSD doesn’t have 7.0 so I couldn’t go back any further, but 13 does support 7.1. Well, here’s my ugly error I can’t solve:

{'app': 'index',
 'level': 3,
 'message': 'Exception: {"Exception":"Error","Message":"Call to undefined '
            'function '
            'OC\\\\Files\\\\Storage\\\\filter_var()","Code":0,"Trace":"#0 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Storage\\\\/Common.php(544): '
            "OC\\\\Files\\\\Storage\\\\Common->scanForInvalidCharacters('merged-template...', "
            "'\\\\\\\\\\\\/')\\n#1 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Storage\\\\/Common.php(535): '
            "OC\\\\Files\\\\Storage\\\\Common->verifyPosixPath('merged-template...')\\n#2 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Storage\\\\/Wrapper\\\\/Wrapper.php(545): '
            "OC\\\\Files\\\\Storage\\\\Common->verifyPath('appdata_ocivszl...', "
            "'merged-template...')\\n#3 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Cache\\\\/Scanner.php(134): '
            "OC\\\\Files\\\\Storage\\\\Wrapper\\\\Wrapper->verifyPath('appdata_ocivszl...', "
            "'merged-template...')\\n#4 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Cache\\\\/Scanner.php(336): '
            "OC\\\\Files\\\\Cache\\\\Scanner->scanFile('appdata_ocivszl...', "
            '3, -1, NULL, false)\\n#5 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Cache\\\\/Updater.php(124): '
            "OC\\\\Files\\\\Cache\\\\Scanner->scan('appdata_ocivszl...', "
            'false, 3, false)\\n#6 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/View.php(319): '
            "OC\\\\Files\\\\Cache\\\\Updater->update('appdata_ocivszl...', "
            '1563075801)\\n#7 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/View.php(1169): '
            'OC\\\\Files\\\\View->writeUpdate(Object(OCA\\\\Files_Trashbin\\\\Storage), '
            "'appdata_ocivszl...')\\n#8 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/View.php(688): '
            "OC\\\\Files\\\\View->basicOperation('file_put_conten...', "
            "'\\\\/appdata_ocivsz...', Array, '(function($) {\\\\n...')\\n#9 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Node\\\\/File.php(64): '
            "OC\\\\Files\\\\View->file_put_contents('\\\\/appdata_ocivsz...', "
            "'(function($) {\\\\n...')\\n#10 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/SimpleFS\\\\/SimpleFile.php(104): '
            "OC\\\\Files\\\\Node\\\\File->putContent('(function($) "
            "{\\\\n...')\\n#11 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Template\\\\/JSCombiner.php(194): '
            "OC\\\\Files\\\\SimpleFS\\\\SimpleFile->putContent('(function($) "
            "{\\\\n...')\\n#12 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Template\\\\/JSCombiner.php(103): '
            "OC\\\\Template\\\\JSCombiner->cache('\\\\/usr\\\\/local\\\\/www\\\\/...', "
            "'merged-template...', "
            'Object(OC\\\\Files\\\\SimpleFS\\\\SimpleFolder))\\n#13 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Template\\\\/JSResourceLocator.php(114): '
            "OC\\\\Template\\\\JSCombiner->process('\\\\/usr\\\\/local\\\\/www\\\\/...', "
            "'core\\\\/js\\\\/merged-...', 'core')\\n#14 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Template\\\\/JSResourceLocator.php(70): '
            "OC\\\\Template\\\\JSResourceLocator->cacheAndAppendCombineJsonIfExist('\\\\/usr\\\\/local\\\\/www\\\\/...', "
            "'core\\\\/js\\\\/merged-...')\\n#15 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Template\\\\/ResourceLocator.php(78): '
            "OC\\\\Template\\\\JSResourceLocator->doFind('js\\\\/merged-templ...')\\n#16 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/TemplateLayout.php(306): '
            'OC\\\\Template\\\\ResourceLocator->find(Array)\\n#17 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/TemplateLayout.php(146): '
            'OC\\\\TemplateLayout::findJavascriptFiles(Array)\\n#18 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/legacy\\\\/template.php(207): '
            "OC\\\\TemplateLayout->__construct('guest', 'core')\\n#19 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/public\\\\/AppFramework\\\\/Http\\\\/TemplateResponse.php(157): '
            'OC_Template->fetchPage()\\n#20 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/AppFramework\\\\/Http\\\\/Dispatcher.php(114): '
            'OCP\\\\AppFramework\\\\Http\\\\TemplateResponse->render()\\n#21 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/AppFramework\\\\/App.php(115): '
            'OC\\\\AppFramework\\\\Http\\\\Dispatcher->dispatch(Object(OC\\\\Core\\\\Controller\\\\LoginController), '
            "'showLoginForm')\\n#22 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/AppFramework\\\\/Routing\\\\/RouteActionHandler.php(47): '
            "OC\\\\AppFramework\\\\App::main('OC\\\\\\\\Core\\\\\\\\Control...', "
            "'showLoginForm', "
            'Object(OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer), '
            'Array)\\n#23 [internal function]: '
            'OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler->__invoke(Array)\\n#24 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Route\\\\/Router.php(297): '
            'call_user_func(Object(OC\\\\AppFramework\\\\Routing\\\\RouteActionHandler), '
            'Array)\\n#25 '
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/base.php(999): '
            "OC\\\\Route\\\\Router->match('\\\\/login')\\n#26 "
            '\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/index.php(42): '
            'OC::handleRequest()\\n#27 '
            '{main}","File":"\\\\/usr\\\\/local\\\\/www\\\\/nginx-dist\\\\/nextcloud\\\\/lib\\\\/private\\\\/Files\\\\/Storage\\\\/Common.php","Line":563}',
 'method': 'GET',
 'remoteAddr': '192.168.10.136',
 'reqId': '',
 'time': '2019-07-14T03:43:21+00:00',
 'url': '\\/login',
 'user': '--',
 'userAgent': 'Mozilla\\/5.0 (X11; Linux x86_64; rv:69.0) Gecko\\/20100101 '
              'Firefox\\/69.0',
 'version': '13.0.12.1'}

I’m rather at a loss with this one…thought maybe an upgrade to 14.x would work but I didn’t have luck there either. Errors out at occ upgrade. (All nextcloud is in a jail and snapshotted so I’ve been able to rollback).

Here’s my nginx.conf file:

user www;
worker_processes        3;

error_log       /var/log/nginx/error.log;

events {
        worker_connections 1024;
}

http {

        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        keepalive_timeout 70;
        #add_header Strict-Transport_security "max-age=15552000; includeSubDomains; preload";

        upstream php-handler {
                server unix:/var/run/php-fpm.sock;
        }

        server_tokens   off;
        access_log      /var/log/nginx/access.log;

    server {
        listen 80;
        root /usr/local/www/nginx-dist/nextcloud;
        server_name mydomain.org;
        # enforce https
        return 301 https://$server_name$request_uri;

        location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
        }
        location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
        }

        # set max upload size
        client_max_body_size 6144M;
        fastcgi_buffers 64 4K;

        location ~ ^/.well-known/acme-challenge/* {
            allow all;
        }
        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

    }

    server {
        listen 443 ssl;
        server_name mydomain.org;

        ################# MY STUFF ######################

        ssl_certificate /usr/local/etc/letsencrypt/live/mydomain.org/fullchain.pem;
        ssl_certificate_key /usr/local/etc/letsencrypt/live/mydomain.org/privkey.pem;

            ssl_session_timeout 1d;
            ssl_session_cache shared:SSL:50m;
            ssl_session_tickets off;

            ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
            ssl_prefer_server_ciphers on;
            ssl_dhparam /usr/local/etc/ssl/dhparam.pem;
            ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';



            # OCSP Stapling ---
            # fetch OCSP records from URL in ssl_certificate and cache them
            ssl_stapling on;
            ssl_stapling_verify on;


        ################# MY STUFF ENDS ################

        # Add headers to serve security related headers
        # Before enabling Strict-Transport-Security headers please read into this
        # topic first.
        # add_header Strict-Transport-Security "max-age=15768000;
        # includeSubDomains; preload;";
        #
        # WARNING: Only add the preload option once you read about
        # the consequences in https://hstspreload.org/. This option
        # will add the domain to a hardcoded list that is shipped
        # in all major browsers and getting removed from this list
        # could take several months.
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header Referrer-Policy "no-referrer";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        #add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;

        # Path to the root of your installation
        root /usr/local/www/nginx-dist/nextcloud;

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        # The following 2 rules are only needed for the user_webfinger app.
        # Uncomment it if you're planning to use this app.
        #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
        #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
        # last;


        location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
        }
        location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
        }

        # set max upload size
        client_max_body_size 6144M;
        #fastcgi_buffers 64 4K;
        fastcgi_buffers 128 1M;
        fastcgi_buffer_size 128K;
        sendfile    on;

        # Enable gzip but do not remove ETag headers
        gzip on;
        gzip_vary on;
        gzip_comp_level 2;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json 
application/rss+xml 
    application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json 
application/xhtml+xml 
    application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard 
text/vnd.rim.location.xloc 
    text/vtt text/x-component text/x-cross-domain-policy;

        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;


        location / {
            rewrite ^ /index.php$uri;
        }


        location '/.well-known/acme-challenge/*' {
            allow all;
        }


        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~ ^/(?:index|remote|login|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            #Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }

        location ~ ^/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }


        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~ \.(?:css|js|woff|svg|gif)$ {
            try_files $uri /index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=15778463";
            # Add headers to serve security related headers (It is intended to
            # have those duplicated to the ones above)
            # Before enabling Strict-Transport-Security headers please read into
            # this topic first.
            # add_header Strict-Transport-Security "max-age=15768000;
            #  includeSubDomains; preload;";
            #
            # WARNING: Only add the preload option once you read about
            # the consequences in https://hstspreload.org/. This option
            # will add the domain to a hardcoded list that is shipped
            # in all major browsers and getting removed from this list
            # could take several months.
            add_header X-Content-Type-Options nosniff;
            add_header X-XSS-Protection "1; mode=block";
            add_header X-Robots-Tag none;
            add_header X-Download-Options noopen;
            add_header X-Permitted-Cross-Domain-Policies none;
            #add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload";
            add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
            # Optional: Don't log access to assets
            access_log off;
        }

        location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
            try_files $uri /index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

The configuration files are a working set of config files from another NC instance I use that has been in place since Nextcloud 12, I just fit in the data that needs to be changed for this instance (such as domain names)…the working host is also FreeBSD, nginx, mariadb 10.3…but it’s using php7.2 so the working host is very similar to the one that’s being migrated to (working host is currently NC16)

Still stuck on this one. This time I decided to attempt a manual upgrade and this is the error I got following the nextcloud instructions here:

An unhandled exception has been thrown:
Error: Call to undefined function OC\Files\Storage\filter_var() in /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Storage/Common.php:567
Stack trace:
#0 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Storage/Common.php(548): OC\Files\Storage\Common->scanForInvalidCharacters('icons', '\\/')
#1 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Storage/Common.php(539): OC\Files\Storage\Common->verifyPosixPath('icons')
#2 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php(545): OC\Files\Storage\Common->verifyPath('appdata_ocivszl...', 'icons')
#3 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Cache/Scanner.php(134): OC\Files\Storage\Wrapper\Wrapper->verifyPath('appdata_ocivszl...', 'icons')
#4 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Cache/Scanner.php(336): OC\Files\Cache\Scanner->scanFile('appdata_ocivszl...', 3, -1, NULL, false)
#5 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Cache/Updater.php(124): OC\Files\Cache\Scanner->scan('appdata_ocivszl...', false, 3, false)
#6 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/View.php(321): OC\Files\Cache\Updater->update('appdata_ocivszl...', 1563240887)
#7 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/View.php(1169): OC\Files\View->writeUpdate(Object(OCA\Files_Trashbin\Storage), 'appdata_ocivszl...')
#8 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/View.php(269): OC\Files\View->basicOperation('mkdir', '/appdata_ocivsz...', Array)
#9 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/Node/Folder.php(161): OC\Files\View->mkdir('/appdata_ocivsz...')
#10 /usr/local/www/nginx-dist/nextcloud/lib/private/Files/AppData/AppData.php(114): OC\Files\Node\Folder->newFolder('icons')
#11 /usr/local/www/nginx-dist/nextcloud/lib/private/Template/IconsCacher.php(78): OC\Files\AppData\AppData->newFolder('icons')
#12 [internal function]: OC\Template\IconsCacher->__construct(Object(OC\Log), Object(OC\Files\AppData\Factory), Object(OC\URLGenerator), Object(OC\AppFramework\Utility\TimeFactory))
#13 /usr/local/www/nginx-dist/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(81): ReflectionClass->newInstanceArgs(Array)
#14 /usr/local/www/nginx-dist/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(98): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#15 /usr/local/www/nginx-dist/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(119): OC\AppFramework\Utility\SimpleContainer->resolve('OC\\Template\\Ico...')
#16 /usr/local/www/nginx-dist/nextcloud/lib/private/ServerContainer.php(132): OC\AppFramework\Utility\SimpleContainer->query('OC\\Template\\Ico...')
#17 /usr/local/www/nginx-dist/nextcloud/lib/private/Server.php(969): OC\ServerContainer->query('OC\\Template\\Ico...')
#18 /usr/local/www/nginx-dist/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC\{closure}(Object(OC\Server))
#19 /usr/local/www/nginx-dist/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(117): Pimple\Container->offsetGet('OC\\Template\\SCS...')
#20 /usr/local/www/nginx-dist/nextcloud/lib/private/ServerContainer.php(132): OC\AppFramework\Utility\SimpleContainer->query('OC\\Template\\SCS...')
#21 /usr/local/www/nginx-dist/nextcloud/lib/private/Repair.php(140): OC\ServerContainer->query('OC\\Template\\SCS...')
#22 /usr/local/www/nginx-dist/nextcloud/core/register_command.php(143): OC\Repair::getRepairSteps()
#23 /usr/local/www/nginx-dist/nextcloud/lib/private/Console/Application.php(118): require_once('/usr/local/www/...')
#24 /usr/local/www/nginx-dist/nextcloud/console.php(95): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /usr/local/www/nginx-dist/nextcloud/occ(11): require_once('/usr/local/www/...')
#26 {main}

Solved it. I was missing a couple php packages that aren’t listed in the documentation for FreeBSD:

  • php71-mysqli
  • php71-filter
  • php71-xsl
  • php71-wddx

Then I found brute force protection was blocking me so I removed the packages from the apps directory. @jospoortvliet would you consider having these packages in the Nextcloud docs for those who choose to go the FreeBSD route?

Glad you got that worked out. You might consider migrating to Docker next time you make a move. It’s highly unlikely you’d run into an issue such as this because all the dependencies are included with the image.

Docker is the last complicated tool I want to add to my stack I’m afraid. Useless, insecure bloat