So far I’ve been on various forums and sites because of the same problem "How do I move my Nextcloud data from /var/www/nextcloud/data to an external hard drive, for example ( /media/USB-Platte/nextcloud/data).
Many posts suggest that you create a folder on the external hard drive and then assign the values (command line) “chown -R www-data:www-data /folder/data” to it, but as many people know, this doesn’t really work .
I literally spent 24 hours trying different variations and seeing what the problem was.
Here is my solution that I made for a standard nextcloud installation on an Ubuntu server 22.04 with mysql.
You need an external hard drive that should have a Linux format like EXT4 and not a windows format.
The disk should be mounted by Ubuntu right at startup, that’s important.
There you now create a folder, in my case that would be nextcloud/data.
Now open the console, navigate to the external hard drive directory and enter the following command “chown -R www-data:www-data /nextcloud/data/”
Now create a kind of link between the two folders, i.e. from /var/www/nextcloud/data to /media/USB-Platte/nextcloud/data (you have to look for the address of your folder path yourself).
This won’t work over symlink, so we’ll use a different method in this case.
The command for this is “sudo mount --bind /media/USB-Platte/nextcloud/data /var/www/nextcloud/data”
(sudo mount --bind /yourexternaldriver/nextcloud/data /var/www/nextcloud/data)
You bind the folder /var/www/nextcloud/data to /yourexternaldriver/nextcloud/data so that the folder is only there symbolically.
That worked for me so far, it’s similar to Docker, where you can also choose where you can bind a folder under the Volume category.