Permissions Issue with Data Storage "Snap" - Solved

Hi,
I’m new to Nextcloud so I installed it via "Snap"to an existing Ubuntu installation. But before I installed NextCloud I added an additional 2 gig hard drive for data storage.

I followed this tutorial: https://linuxhint.com/install_nextcloud_ubuntu/ and everything seemed to go ok. I then followed this tutorial: Tutorial: How to migrate mass data to a new NextCloud server to migrate some files and data. Everything seemed to go fine until I needed to run this command:

cd /var/www/nextcloud
sudo -u www-data php console.php files:scan --all

With the install via Snap I didn’t have a WWW directory. So after a little searching I came up with these commands below. All three scan commands get the same output listed below.

The data is on the drive, I can see it on a file browser but I can’t see it on a web browser. I can’t get a scan to work. I think I have a permissions issue with my data drive. Please see below. Can someone please help me with this?

bart@bart-Server:~$ sudo df -h | grep nextcloud
[sudo] password for bart:
/dev/loop4 233M 233M 0 100% /snap/nextcloud/20498
/dev/sda1 1.8T 526G 1.2T 31% /var/snap/nextcloud/common/nextcloud/data
bart@bart-Server:~$

bart@bart-Server:~$ sudo nextcloud.occ files:scan --all
bart@bart-Server:~$ sudo nextcloud.occ files:scan

bart@bart-Server:~$ sudo /snap/bin/nextcloud.occ files:scan --all
[sudo] password for bart:
Your data directory is not writable
Permissions can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/18/go.php?to=admin-dir_permissions.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /snap/nextcloud/20498/htdocs/lib/private/Console/Application.php:167
Stack trace:
#0 /snap/nextcloud/20498/htdocs/console.php(98): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /snap/nextcloud/20498/htdocs/occ(11): require_once(’/snap/nextcloud…’)

After a week of investigation I have finally solved this problem. I used these commands:

$ sudo snap disable nextcloud

$ sudo chown -R root:root /media//<hard_drive_name>/nextcloud_data_directory

$ sudo chmod -R 0770 /media//<hard_drive_name>/nextcloud_data_directory
Re-enable your Nextcloud server
$ sudo snap enable nextcloud
$ sudo nextcloud.occ files:scan --all

2 Likes

I honestly only made this account to comment on this. The search for a solution to my problem has finaly come to an end after days! THANK YOU SO MUCH!!!

1 Like

Sorry, but I still get
“Exception during scan: opendir(my_data_dir): failed to open dir: Permission denied”

Both ownership and permissions are ok, root:root and 0770. Files are writable from root. So I don’t understand why there is a permission problem. Does nextcloud.occ run under another account?

Hi wa_bo, I’m not the best qualified to help but for anyone to understand your problem you will have to provide more information. I ended up deleting my snap install as there was very little help on the forum for snap installs. I did a re-install following this how to guide:
https://riegers.in/nextcloud-installation-guide-ubuntu-20-04/

It was very easy to follow and worked straight away and any issues that I have had there seems to be more information out there for the conventional install. He also has another method of install which I try next time. See link below.
https://riegers.in/install-nextcloud-18-using-one-script-only/

But as I said before, if you want to solve your snap install we would need more information. I hope this helps.

Thanks for your fast reply!

I have searched around at it seems as it boils down to that snap installations are not allowed to reach outside the snap environment, at least not without extra measures. Regardless of the ownership and permissions on the external drive.

Thanks very much for the links. I’ll study the carefully!