2

I am trying to make a php script on a webserver write into a folder /data on a fileserver.

Apache 2.2, PhP 5.x. It's just a test configuration but I'd like to understand the thing somehow as I am not very experienced regarding permissions when it comes to webservers.

I am sharing the folder /data on the fileserver by adding

/data 192.168.20.6(rw,sync,no_subtree_check) 

Mount the folder by

sudo mount 192.168.20.5:/data /mnt/data 

Create a link to the webroot(does that makes sense at all?)

sudo ln -s /mnt/data /webroot/site1/share 

Then I get this:

Warning: fopen(/webroot/site1/share/data/uploads/Fotoraum/Original/Bluehend/test.txt): failed to open stream: Permission denied 

Where and how do I have to adjust permissions in a sane manner to allow the script to write into /data and its subfolders?

Thanks a lot!

10
  • I suppose the warning is from a webserver? They typically run under a separate user, e.g. www. You mounted using sudo, hence the mountpoint is owned by root. Please post the output of ls -ld /mnt/data and su <www-user>; touch /webroot/site1/share/foo.txt Commented Sep 9, 2014 at 21:26
  • btw, using a mounted nfs volume might not be a very good idea: (a) if the fileserver is offline, the webservice stops working (b) network/server latency. Perhaps it's better store the files locally and then sync them over regularily? Commented Sep 9, 2014 at 21:30
  • make sure that user that is creating a link has ownership of data folder. Commented Sep 9, 2014 at 21:59
  • mammal here :) @sebastian drwxr-xr-x 14 nobody nogroup 4096 Sep 9 22:36 /mnt/data Commented Sep 11, 2014 at 18:32
  • @sebastian Doing the ls -ld on the link gives me this lrwxrwxrwx 1 root root 9 Sep 11 21:54 data -> /mnt/data btw the files that we put on the nfs are just the huge original files of the pictures we store. Smaller resized versions are on local storage ;) To behonest, I don't know who the www-user is... Commented Sep 11, 2014 at 20:00

2 Answers 2

0

per your comment I think the following option is better than chmod -R 775 /mnt/data

when using mount, you can specify the user and group which owns the files, maybe you want to use the following:

sudo mount 192.168.20.5:/data /mnt/data -o uid=<uid-of-www-data>,gid=<gid-of-www-data> 

the values uid and gid of www-data can be found in /etc/passwd and /etc/group.

1
  • The uid and gid options do not apply to NFS mounts. (Perhaps you're confusing NTFS?) Commented Aug 22, 2017 at 22:54
0

You can do chmod 6777 on the shared folder from the nfs server, so that any files being created on the file belongs to the owner group of the folder.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.