New nextcloud installation and old data

I use nextcloud and everything works great. Nextcloud is installed in LXC debian 11.
I have the data directory in the ZFS pool outside of nextcloud.
I want to build nextcloud on the new LXC Debian 12. I never update, but always install a new OS.
I have the old nextclod LXC backed up and I can always restore it.
I installed debian 12 and nextcloud hub in LXC.

https://download.nextcloud.com/server/installer/setup-nextcloud.php

During the installation, I set the data directory to

/var/www/nextcloud-data

After installation, I have this in the data directory
nove-data

Everything works correctly, but I want to connect the old data directory. The old data directory is stored on another ZFS pool

I understand that I have to connect the old data directory to LXC

mp0: /datapool/nextcloud,mp=/var/www/nextcloud-data

When I do that, I can’t connect to the web browser and see

Configuration was not read or initialized correctly, not overwriting /var/www/html/www.example.com/config/config.php

I used config.php from the old nextcloud, but the error is always the same.
What procedure should I choose if I want to install the new nextcloud and use the old data?

You just want the files restored for the users, no sharing no app data? And the clients will resync all the files again from nothing…? I’d do a fresh setup, create all the users, then copy the files for each user back and run the occ files:scan. I wouldn’t bother with the config.php, there is just a risk that you copy some old stuff that creates problems later.

If the php versions allow it, then you can migrate your complete Nextcloud setup on the machine with the new operating system. No resync needed, everything as it should be. E.g. on Debian 11, you update until NC 25 (lastest possible with php7.4), then you migrate to Debian 12 and directly run your upgrade to NC 26 which supports php 8.2. Or on Debian 11, you install some php 8.x version to go up to NC 26.

My old system

  • Nextcloud Hub 4 (26.0.1)
  • Ver. PHP: 8.0.28
  • Apache/2.4.56 (Debian)
  • 10.5.21-MariaDB

New system

  • Last Nextcloud Hub
  • Ver. PHP 8.2.11
  • Apache/2.4.57 (Debian)
  • 10.11.4-MariaDB

In your opinion, can I somehow create a full backup, including the database, on the old server?
Can I restore this backup on the new server (debian 12)?

I backed up the database and the nextcloud root directory on the old server. I installed a new server (apache2, php-fpm, mariadb). I mounted the data directory in the LXC. I can see all the files in the mounted directory. I restored the database and the root nextcloud directory.

reboot

I can still see it in the browser

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Did I forget something?

The migration between the setups is possible and your procedure looks good so far. For the internal server error, you have to check the logs (Nextcloud and/or webserver). Can be a permission problem with the files, database connection, missing php modules, …

Sometimes you can find the “internal Server Error” if you try to execute the index.php on command line although this is of course something completely different.

sudo -u www-data php /path/to/nextcloud/index.php

Normally you can better look in the webserver logs.

Remember, of course, that you have to run the identical Nextcloud version on the old and the new server.

Everything seems to be fine, but …
If I put info about php in the root directory

sudo echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/www.example.com/index.php

I see information about php.
If I extract to the nextcloud root directory from the old server, I get an error

sudo tar xvzf ~/backup_nextcloud-2023-10-24-17.05.05.tar.gz -C /
Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Regardless of whether I have a database or not, I should see at least some files on the web

http://www.example.com/remote.php
http://www.example.com/public.php
http://www.example.com/status.php

etc.

I always see though Internal Server Error.

File Privilege and Owner

ls -la /var/www/html/www.example.com/config
total 68
drwxr-xr-x  2 www-data www-data     7 Aug 27 05:28 .
drwxr-xr-x 15 www-data www-data    29 Oct 25 21:06 ..
-rw-r-----  1 www-data www-data  1155 Aug 24 15:43 config.php
-rw-r--r--  1 www-data www-data 74851 May 10 10:19 config.sample.php
-rw-r--r--  1 www-data www-data   495 May 10 10:19 .htaccess
-rw-r--r--  1 www-data www-data    78 May 10 10:27 mimetypealiases.json
-rw-r--r--  1 www-data www-data   110 May 10 10:27 mimetypemapping.json

ls -la /var/www/html/www.example.com
total 203
drwxr-xr-x 15 www-data www-data    29 May 10 10:19 .
drwxr-xr-x  4 www-data www-data     5 Apr  5  2023 ..
drwxr-xr-x 45 www-data www-data    52 May 10 10:19 3rdparty
drwxr-xr-x 52 www-data www-data    52 May 10 10:27 apps
-rw-r--r--  1 www-data www-data 19327 May 10 10:19 AUTHORS
drwxr-xr-x  2 www-data www-data     7 Aug 27 05:28 config
-rw-r--r--  1 www-data www-data  4095 May 10 10:19 console.php
-rw-r--r--  1 www-data www-data 34520 May 10 10:19 COPYING
drwxr-xr-x 24 www-data www-data    30 May 10 10:19 core
-rw-r--r--  1 www-data www-data  6317 May 10 10:19 cron.php
drwxr-xr-x  2 www-data www-data     5 Aug 27  2021 data
drwxr-xr-x  2 www-data www-data   168 May 10 10:19 dist
-rw-r--r--  1 www-data www-data  3386 May 10 10:19 .htaccess
-rw-r--r--  1 www-data www-data   156 May 10 10:19 index.html
-rw-r--r--  1 www-data www-data  3456 May 10 10:19 index.php
drwxr-xr-x  6 www-data www-data     9 May 10 10:19 lib
-rw-r--r--  1 www-data www-data   283 May 10 10:19 occ
drwxr-xr-x  2 www-data www-data     3 May 10 10:19 ocm-provider
drwxr-xr-x  2 www-data www-data     5 May 10 10:19 ocs
drwxr-xr-x  2 www-data www-data     3 May 10 10:19 ocs-provider
-rw-r--r--  1 www-data www-data  3187 May 10 10:19 public.php
-rw-r--r--  1 www-data www-data  5597 May 10 10:19 remote.php
drwxr-xr-x  4 www-data www-data     8 May 10 10:19 resources
-rw-r--r--  1 www-data www-data    26 May 10 10:19 robots.txt
-rw-r--r--  1 www-data www-data  2452 May 10 10:19 status.php
drwxr-xr-x  3 www-data www-data     4 May 10 10:19 themes
drwxr-xr-x  2 www-data www-data     4 Jan 16  2022 updater
-rw-r--r--  1 www-data www-data   101 May 10 10:19 .user.ini
-rw-r--r--  1 www-data www-data   383 May 10 10:19 version.php

The database on the old server was backed up as follows

sudo mysqldump nextcloud > ~/nextcloud-$(date +%Y-%m-%d-%H.%M.%S).sql

On the new server

sudo mysql -e 'DROP DATABASE IF EXISTS `nextcloud`'
sudo mysql -e 'CREATE DATABASE `nextcloud`'
sudo mysql  nextcloud < nextcloud-2023-10-24-17.03.39.sql

logs

cat /var/log/apache2/example.error

[Tue Oct 24 16:32:45.845645 2023] [autoindex:error] [pid 658:tid 140477282109120] [client 192.168.20.10:35514] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Tue Oct 24 16:32:49.575467 2023] [autoindex:error] [pid 657:tid 140477385107136] [client 192.168.20.10:54228] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Tue Oct 24 16:32:53.457906 2023] [proxy_fcgi:error] [pid 657:tid 140477401892544] [client 192.168.20.10:54246] AH01071: Got error 'Primary script unknown'
[Tue Oct 24 16:32:55.559757 2023] [proxy_fcgi:error] [pid 657:tid 140477298894528] [client 192.168.20.10:54268] AH01071: Got error 'Primary script unknown'
[Wed Oct 25 20:05:53.412777 2023] [proxy_fcgi:error] [pid 545:tid 139749796845248] [client 192.168.20.10:57578] AH01071: Got error 'Primary script unknown'
[Wed Oct 25 20:05:57.876256 2023] [autoindex:error] [pid 545:tid 139749780059840] [client 192.168.20.10:51732] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Wed Oct 25 20:08:56.454724 2023] [autoindex:error] [pid 202:tid 140490761533120] [client 192.168.20.10:34290] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Wed Oct 25 20:08:57.507025 2023] [autoindex:error] [pid 203:tid 140490645165760] [client 192.168.20.10:48232] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Wed Oct 25 20:08:58.128875 2023] [autoindex:error] [pid 203:tid 140490628380352] [client 192.168.20.10:48248] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
[Wed Oct 25 20:22:31.600223 2023] [proxy_fcgi:error] [pid 203:tid 140490494097088] [client 192.168.20.10:38094] AH01071: Got error 'Primary script unknown'
[Wed Oct 25 20:22:35.986416 2023] [autoindex:error] [pid 203:tid 140490661951168] [client 192.168.20.10:38100] AH01276: Cannot serve directory /var/www/html/www.example.com/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive

cat /var/www/html/www.example.com/data/nextcloud.log

{"reqId":"53f10A6KyYSfvOZiDVEN","level":2,"time":"2021-08-27T19:17:21+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}
{"reqId":"53f10A6KyYSfvOZiDVEN","level":2,"time":"2021-08-27T19:17:21+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"GET","url":"/","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}
{"reqId":"dleK0SwlQ96ZNlNwkUVA","level":2,"time":"2021-08-27T19:17:23+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"GET","url":"/index.php/apps/photos/service-worker.js","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}
{"reqId":"dleK0SwlQ96ZNlNwkUVA","level":2,"time":"2021-08-27T19:17:23+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"GET","url":"/index.php/apps/photos/service-worker.js","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}
{"reqId":"84jh8jrZ9YLg0erm6tkz","level":2,"time":"2021-08-27T19:18:10+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Could not detect any host in http:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}
{"reqId":"84jh8jrZ9YLg0erm6tkz","level":2,"time":"2021-08-27T19:18:10+00:00","remoteAddr":"192.168.1.1","user":"--","app":"no app in context","method":"POST","url":"/index.php","message":"Could not detect any host in https:///data/htaccesstest.txt","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","version":""}

The permissions look ok.
Did you add something to your apache config to the vhost?
https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#apache-web-server-configuration

(second blue boxm the first one is if you have it in a subfolder (example.com/nextcloud).
If you use php-fpm (and not the apache php module), check out the configuration notes further down in the same document.

try to rename the appdata_234zr98f982349 to the name of your previous instance or copy the folder from your old instance to the datapool.
Check your config.php for matching app data_id -
Easy way: copy appdata and config php from your old instance to the new one, fix permissions and you should be up and running

tflidd
I also transferred the vhost from the old server

<VirtualHost *:80>
        DocumentRoot "/var/www/html/www.example.com.info"
        ServerName www.example.com.info

        ErrorLog ${APACHE_LOG_DIR}/example.error
        CustomLog ${APACHE_LOG_DIR}/example.access combined

        <Directory /var/www/html/www.example.com.info/>
            Require all granted
            Options FollowSymlinks MultiViews
            AllowOverride All

           <IfModule mod_dav.c>
               Dav off
           </IfModule>

        SetEnv HOME /var/www/html/www.example.com.info
        SetEnv HTTP_HOME /var/www/html/www.example.com.info
        Satisfy Any

       </Directory>
      RemoteIPHeader X-Real-IP
      RemoteIPInternalProxy 192.168.20.10

</VirtualHost>

The Apache2 server is behind the nginx reverse proxy.

Martin_Ho
As I wrote, I host nextcloud in an unprivileged LXC, where I have a mount ZFS pool.

mp0: /datapool/nextcloud,mp=/var/www/nextcloud-data

The original appdata_xxx directory exists there. why should I rename it?
I do not understand this

Easy way: copy appdata and config php from your old instance to the new one, fix permissions and you should be up and running