Centos – Mounted NFS directory not writable by Apache / PHP

centosmountnfspermissionsselinux

Need some help here with NFS. Here's what I have (all servers running CentOS 5.6 with SELinux):

172.17.20.1 - Primary server with static IP. Varnish redirects requests to the web servers.
172.17.20.2 - Web server 1
172.17.20.3 - Web server 2

The application residing on the web servers is running Drupal and I need both of them to share the same files directory. I have created a folder in 172.17.20.1 called /var/nfs with root user. Here is my /etc/exports content:

/var/nfs    172.17.20.2(rw,sync,no_root_squash) 172.17.20.3(rw,sync,no_root_squash)

On both the web servers (172.17.20.2/3), I have it mounted like below:

[root@web2 ~]# mount
...
172.17.20.1:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,addr=172.17.20.1)

On all the servers, I've added the user apache to the root group to get the desired write access:

[root@main ~]# cat /etc/group
root:x:0:root,apache
....
....
apache:x:48:

[root@web1 ~]# cat /etc/group
root:x:0:root,apache
....
....
apache:x:48:

Folder permission on main:

drwxrwxr-x  4 root root 4096 Mar 11 15:49 nfs

Folder permission on web servers:

drwxrwxrwx   3 apache apache  4096 Feb 18 13:51 mnt

Despite all this, when I try to write files into the /mnt/nfs/var/nfs folder from Drupal/PHP, it cannot write to it. I even tried with a simple PHP upload script but it doesn't work, so the problem is not with Drupal.

Any help you guys can do is much appreciated. I've spent hours and hours with it, without any success 🙁

Thanks in advance.

Best Answer

I've added the user apache to the root group to get the desired write access

But you've not shown us what the permissions are on the files / directories. (and BTW this is not a good idea from a security stand point - similar for no_root_squash).

Why sync?