Accessing local folders

What is the best way to access folders that are outside Nextcloud default data folder but are located on the same disk/server? Is there any other way or I have to use “external storages” plugin?

I’ve followed this wiki instructions but its not working for me: https://docs.nextcloud.com/server/15/admin_manual/configuration_files/external_storage/local.html

I’m getting this error in the Nextcloud log and red exclamation mark is shown when I want to add the new path:

Error PHP stat(): stat failed for /home/user/pictures/ at /srv/nextcloud/lib/private/Files/Storage/Local.php#143

I’ve double checked and the permissions are correct.

I’m using Nextcloud 17. Any ideas?

Also these are the warnings I see in the overview tab, anything to worry about?

* MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read [the documentation page about this](https://docs.nextcloud.com/server/17/go.php?to=admin-mysql-utf8mb4).
* The "X-Robots-Tag" HTTP header is not set to "none". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.
* The "X-Download-Options" HTTP header is not set to "noopen". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.
* The "X-Permitted-Cross-Domain-Policies" HTTP header is not set to "none". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.
* The "X-XSS-Protection" HTTP header doesn't contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.
* The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the [security tips ↗](https://docs.nextcloud.com/server/17/go.php?to=admin-security).

* No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the [documentation](https://docs.nextcloud.com/server/17/go.php?to=admin-performance).
* This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.
`imagick`
* The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the [W3C Recommendation ↗](https://www.w3.org/TR/referrer-policy/).```

should be fine.

the folder belongs to the webserver user/group or has 0777?

you’ll find that in the doc. “how to setup mysql”

inhouse aka at home. don’t care. access over the internet? you’ll find infos about the correct settings for your webserver in the docs.

one or two user? don’t care. performance problems: install redis and configure it in config.php. (it’s in the docs. :wink: )

what do to depends on your setup. (os and webserver)

Thanks for tips :slight_smile:

Yes, I did it like this again now, and it still doesn’t work:
sudo chmod -R 0777 /home/user/pictures

you must have the right permission settings for the parent folder as well, check if the webserver-user can access the folder:

sudo -u webserver-user ls /home/user/pictures

You are right, I get permission denied. How do I give it access then? The folder I want to access is in the home directory of another user (different than webserver user).

you have to give the webserver user permission, e.g. putting him in the same group or something. But if there is a security issue, the webserver can possibly read the whole personal folder. It would be a better to mount this drive to a neutral path (like /mnt/pictures), /mnt is readable by everyone and for the /mnt/pictures you can define who owns it and who is in the group to access it. (a user can still access and use a symbolic link to it in his home folder).

Another option is to do a mount --bind of the pictures folder to some place where the webserver can read it.

What would be the best option when you consider that I am running Nextcloud on a remote Ubuntu VPS? And if you could provider exact command that would be great as I am not Linux guru.

Have a look here https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount

So I mounted the folder using:
sudo mount --bind /home/user/pictures /srv/nextcloud/data/user/files/pictures
and I see that it works when I look at the folder through SSH but the Nextcloud doesn’t see the files, it says that folder “pictures” has 0 KB. How do I force Nextcloud to see the files?

Also how do I get this mount to be applied on system boot?
I’ve tried adding it to /etc/fstab but it is not working properly, it seems I’m adding it incorrectly, can anyone tell what would be the exact line that needs to be added to /etc/fstab from the above example?

I think you’re on the right track. What does the following command show once you’ve manually mounted the folder?

mount | grep "pictures"

It shows me this:
/dev/vda1 on /srv/nextcloud/data/user/files/pictures type ext4 (rw,relatime,data=ordered)

Try to add the following line to your /etc/fstab file:

/dev/vda1  /srv/nextcloud/data/user/files/pictures  ext4  rw,relatime,data=ordered  0  0

BTW, there is no need to reboot the server to test it, you can easily un-mount the drive using the following command:

umount /dev/vda1

To mount all entries from the edited /etc/fstab the following command can be used:

mount -a

When I do the above it mounts whole filesystem in the /srv/nextcloud/data/user/files/pictures folder, this is what I see when I ls in that folder:

bin boot dev etc home initrd.img initrd.img.old install lib lib64 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var vmlinuz vmlinuz.old

But why Nextcloud doesn’t see any files when I look through browser UI in the /srv/nextcloud/data/user/files/pictures folder?

Because you first have to make sure that the user under which your web server is running, e.g. “http”, is allowed to access these files and folders. Second you have to scan and import the file structure to the Nextcloud database by running ./occ files:scan [options] [--] [<user_id>...] .

  • Check file permissions ls -laF /srv/nextcloud/data/user/files/pictures and make sure they are readable by your apache/webserver.
  • The folder /srv/nextcloud/data/user/files/pictures itself needs to have executable permission. * Try chmod 0755 /srv/nextcloud/data/user/files/pictures
  • Try chown -R youruser:apache-user /srv/nextcloud/data/user/files/pictures
  • Then issue occ files:scan --all -vvv

Thanks, I ran the occ command and Nextcloud finally displayed files. But whenever there is a change or new files are added in that folder through SSH or other apps, they are not reflected in Nextcloud web UI, how to fix that?

You can use the inotify app. Or schedule occ scan. I believe there is also a config option to check folders automatically.

I get this error when trying to install inotify app:
App "INotify file watcher" cannot be installed because the following dependencies are not fulfilled: The library inotify is not available.

I feel like I’m fighting with windmills here, isn’t sharing files supposed to be one of Nextcloud core functionalities? Why is this so difficult to configure and enable?

Nextcloud is a software which is installed on top of an exiting system not replacing a system. It relies on system components and if you’re not providing this components it couldn’t fulfill its job. So install the missing component and it should work :wink: