Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chgrp : Operation not permitted?

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?

like image 948
Alex.Barylski Avatar asked Mar 20 '23 15:03

Alex.Barylski


2 Answers

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)

like image 148
Flosculus Avatar answered Mar 28 '23 19:03

Flosculus


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.

like image 32
xeo Avatar answered Mar 28 '23 19:03

xeo