php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42711 Unable to chown/chgrp of a symlink
Submitted: 2007-09-19 14:17 UTC Modified: 2007-09-19 19:51 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: arnaud dot lb at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arnaud dot lb at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-19 14:17 UTC] arnaud dot lb at gmail dot com
Description:
------------
There is no way to change the owner or group of a symlink.

Using chown and chgrp functions on a symlink affect the file 
referenced by the symbolic link, rather than the symbolic link 
itself.

There should have a "$dereference" argument to be able to affect the 
file referenced by the symlink or the symlink itself.

Reproduce code:
---------------
<?php
// Setup test files
if (file_exists('test-referent')) unlink('test-referent');
if (file_exists('test-symlink')||is_link('test-symlink')) unlink('test-symlink');
touch('test-referent');
symlink('test-referent', 'test-symlink');
echo shell_exec('chown -h nobody test-symlink test-referent 2>&1');

echo "Original owners: \n";
echo shell_exec("ls -l test-referent test-symlink") . "\n";

// Test changing symlink owner with PHP's chown() function

chown('test-symlink', 'root');

echo "New owners: \n";
echo shell_exec("ls -l test-referent test-symlink");
?>

Expected result:
----------------
chown should affect symlink owner instead of the referenced file

Original owners:
-rw-r--r-- 1 nobody root  0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> 
test-referent

New owners:
-rw-r--r-- 1 nobody   root  0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 root root 13 2007-09-19 16:04 test-symlink -> 
test-referent

Actual result:
--------------
chown has affected the referenced file instead of the symlink itself

Original owners:
-rw-r--r-- 1 nobody root  0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> 
test-referent

New owners:
-rw-r--r-- 1 root   root  0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink -> 
test-referent

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-19 19:51 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to use the lchown() function.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 23:00:03 2025 UTC