4

I've done a bunch of research on this one and there are very different answers. I can't get confident that I won't mess up my Apache settings or cause me not to be able to get to the Volume from Mac Finder after making changes.

Has anyone done this recently that can walk me through the steps to get my PHP/Apache local site on Mac read from an external NAS /Volume. I want to use scandir to read the files list.

The PHP code is simple, and works on my local disk, but not on a /Volume

$path = '/Volumes/Nas/Files';
$files = scandir($path);
print_r($files);

Getting error scandir(/Volumes/Nas/Files): failed to open dir: Permission denied

Thanks.

Jeff Solomon
  • 459
  • 6
  • 21
  • 1
    How can there be "very different answers" for a permission denied error? Grant the user the appropriate permissions. – miken32 Apr 30 '21 at 20:52
  • 1
    So by default OS X mounts the nas with the user mounting it has access. So the apache user is the one actually executing the PHP script it doesn't have access to it. Add privileges to the 'other' permission level for the mount point of the nas. You can try something like this chmod -R o+r /Volumes/Nas – Adi May 05 '21 at 15:30
  • @Adi i'm struggling to give it permissions. I tried the -R o+r /Volumes/Readynas but still not working – Jeff Solomon May 07 '21 at 01:45

1 Answers1

2

Get user name running the php script, see https://www.php.net/manual/en/function.get-current-user.php, and then fix file permissions for that user.

If absolutely needed, you can use bindfs to translate the permissions for your script/user.

mvorisek
  • 3,290
  • 2
  • 18
  • 53
  • I checked the user and added that user to my Netgear ReadyNas as an admin. Still getting the same error. I've tried formatting the share reference in PHP multiple ways, none work. `$path = '\\\\192.168.1.49\\foldername';` `$path = '/Volumes/foldername';` – Jeff Solomon May 04 '21 at 19:53