Question

I have this simple line of code:

      mkdir($path_to_rpi, 0755);
      chgrp($path_to_rpi, 'sambashare');

Directory is created as www-data and group is the same. www-data owns the directory and yet the chgrp fails?!?

What am I missing here?

Was it helpful?

Solution

Confirming my comment:

You must be a member of the group to which you are changing ownership to.

http://unixhelp.ed.ac.uk/tasks/change_own.html

(dead link; use this one: https://theory.uwinnipeg.ca/UNIXhelp/tasks/change_own.html)

OTHER TIPS

Just ran into this myself today. This was the best post on the subject that I found but there is no clear answer, just a few comments of various merit. So here's a concise summary.

--Setup--
User  : apache
Group : web
Goal  : make a new directory 'newone' owned by apache and group of web
Verify: >ls -l shows: drwxr-xr-x 2 apache web  4096  ...   newone

step 1:  apache must be a member of group web (@Flosculus answer)
check : > grep ^web /etc/group
to add: > usermod -a -G web apache

step 2: restart apache (@Andrew Mecidoo comment)
restart: > service httpd restart

step 3: make the directory
PHP: mkdir('newone', 0755);
PHP: chgrp('newone', 'web');

step 4: verify permissions
verify : > ls -l

worked for me. hope it helps you out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top