{"record":{"id":"d292950539a49ced","repo":"yiisoft/yii2","slug":"unable-to-change-group-ownership-of-path-to","errorCode":null,"errorMessage":"Unable to change group ownership of \"{$path}\" to \"{$group}\".","messagePattern":"Unable to change group ownership of \"(.+?)\" to \"(.+?)\"\\.","errorType":"exception","errorClass":"yii\\base\\Exception","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseFileHelper.php","lineNumber":1027,"sourceCode":"        }\n        if ($user !== null && $user !== '') {\n            if (is_numeric($user)) {\n                $user = (int) $user;\n            } elseif (!is_string($user)) {\n                throw new InvalidArgumentException('The user part of $ownership must be an integer, string, or null.');\n            }\n            if (!chown($path, $user)) {\n                throw new Exception('Unable to change user ownership of \"' . $path . '\" to \"' . $user . '\".');\n            }\n        }\n        if ($group !== null && $group !== '') {\n            if (is_numeric($group)) {\n                $group = (int) $group;\n            } elseif (!is_string($group)) {\n                throw new InvalidArgumentException('The group part of $ownership must be an integer, string or null.');\n            }\n            if (!chgrp($path, $group)) {\n                throw new Exception('Unable to change group ownership of \"' . $path . '\" to \"' . $group . '\".');\n            }\n        }\n    }\n}\n","sourceCodeStart":1009,"sourceCodeEnd":1032,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseFileHelper.php#L1009-L1032","documentation":"When chgrp($path, $group) returns false, changeOwnership() throws yii\\base\\Exception with path and group in the message. Changing a group to anything other than one of the process's own groups requires root; chgrp also fails for a nonexistent group or on read-only filesystems. Like error 269 this is a privilege/lookup failure at the filesystem boundary.","triggerScenarios":"An unprivileged process setting a group it does not belong to; a group name/gid that exists on the host but not in the container (or vice versa); group lookup failing through NSS/LDAP; read-only or non-POSIX mounts.","commonSituations":"Deployment scripts chgrp-ing to service groups while running as CI users; Docker containers with different /etc/group contents than the host; shared-hosting sandboxes that forbid group changes.","solutions":["Run the step as root (deploy/entrypoint), or add the target group to the running user first.","Verify the group before calling: posix_getgrnam($group) !== false.","Standardize gids across host/container environments.","Catch the Exception and log path + group for diagnosis."],"exampleFix":"// before\n\\yii\\helpers\\FileHelper::changeOwnership($upload, ['user' => 'app', 'group' => 'dockerhost']);\n\n// after\n$grp = \\posix_getgrnam('app');\nif ($grp === false) {\n    throw new \\RuntimeException(\"Group 'app' not found\");\n}\n\\yii\\helpers\\FileHelper::changeOwnership($upload, ['user' => 'app', 'group' => $grp['gid']]);","handlingStrategy":"try-catch","validationCode":"if (\\function_exists('posix_getgrnam') && \\posix_getgrnam($group) === false) {\n    throw new \\RuntimeException(\"Unknown group: {$group}\");\n}\n\\yii\\helpers\\FileHelper::changeOwnership($path, ['user' => $user, 'group' => $group]);","typeGuard":null,"tryCatchPattern":"try {\n    \\yii\\helpers\\FileHelper::changeOwnership($path, ['group' => $group]);\n} catch (\\yii\\base\\Exception $e) {\n    \\Yii::error(\"chgrp failed (privileges or unknown group): {$e->getMessage()}\", 'files');\n    throw $e;\n}","preventionTips":["chgrp to a group the running user belongs to, or run as root in the deploy pipeline.","Verify group existence with posix_getgrnam() first.","Keep gid maps consistent between host and containers.","Log path + group on failure so privilege issues are diagnosable."],"tags":["ownership","chgrp","privileges","environment","yii2"],"backgroundTag":"chown-permission-denied","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}