First of all, I'm sorry about my bad English, I'm not a native speaker.
I'm using PHP with FCGI, so each one of my virtual hosts run their php scripts as different users.
I needed to share a php class between two of the virtualhosts (user1 and user2), so I decided that adding user2 to user1 group in /etc/group would be a good idea to accomplish that. I did that, and then I tested that the group permissions were working fine with the following command:
su user2
cat /home/user1/shared_class.php
and it worked fine (user2 accessed user1 class just fine).
But PHP didn't seem to recognize that same permission. I saved the following script in user2 virtual host for testing and ran from the browser:
<?php
passthru('whoami');
passthru('cat /home/user1/shared_class.php');
?>
and that returned the correct username ('user2') but not the content of shared_class.php. If I try to require_once('/home/user1/shared_class.php') I also get an "Access Denied" error. So it's clear that PHP thinks 'user2' does not have permission to access shared_class.php.
Another test I did was to run
su user1
chmod o+r /home/user1/shared_class.php
After that last chmod, the 'user2' PHP script could read the file just fine, so I'm certain it's not folder restrictions (open_basedir or some other directive), it's just PHP ignoring /etc/group.
Is this expected? Is there any way to accomplish that?
The workaround I'm using right now was to
su user1
chown user1:user2 /home/user1/shared_class.php
That way, user2 can access the file just fine from php, but I'd like to be able to share the files without having to change the chown settings manually, that is, using /etc/group and adding user2 to user1 group.
Thanks.