php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53658 is_writable returns always false
Submitted: 2011-01-05 22:38 UTC Modified: 2011-01-07 18:10 UTC
From: pierregobin at free dot fr Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.3SVN-2011-01-05 (SVN) OS: Linux 2.6.35
Private report: No CVE-ID: None
 [2011-01-05 22:38 UTC] pierregobin at free dot fr
Description:
------------
When php script is run via apache is_writable always returns false :

'is_writable()' always returns 'false' whatever :
- the permission write sets or not.
- safe_mode on or off
- the owner of the file being root:root or apache:apache

on the other side, 'is_readable()' returns the correct value (either 'true' when the file is made readable or 'false' when the file is made unreadable). 

But, when the same script is run by the php command line (under root) - is_writable returns the correct value.

Test script:
---------------
<?php
if (is_writable("toto")) {
	echo "is_writable<br>";
} else {
	echo "is not writable!!!<br>";
}
?>

Expected result:
----------------
is_writable in case 'toto' is writable
is not writable in case 'toto' is not writable


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-05 23:44 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2011-01-05 23:44 UTC] rasmus@php.net
Are you absolutely sure your web server is running as user apache?  Do a "ps -aux 
| grep httpd" or "ps aux | grep apache" and see which user it is running as.  
is_writable works fine everywhere as far as I know.
 [2011-01-06 23:21 UTC] pierregobin at free dot fr
-Status: Feedback +Status: Open
 [2011-01-06 23:21 UTC] pierregobin at free dot fr
Hi - 

1) apache is the user as shown by ps aux | grep httpd.

apache    1724  0.0  0.8  33996  4248 ?        S    18:00   0:00 /usr/sbin/httpd
apache    1726  0.0  0.6  32972  3292 ?        S    18:00   0:00 /usr/sbin/httpd

2) when I run php on command line using my own account :
php -f is_writable.php - result is correct;

3) when I run php on command line sudoed by apache - it works also (echo is_writable).
sudo -u apache php -f is_writable.php
this echos the right result :
is_writable<br>

Seems like httpd is disturbing php...
 [2011-01-06 23:27 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2011-01-06 23:27 UTC] rasmus@php.net
Nah, this is pure Unix permissions.  You are missing a piece somewhere.  PHP 
doesn't do anything magical here.  selinux perhaps.  Dunno.  strace a request and 
see which low-level syscall is failing here.
 [2011-01-07 18:10 UTC] pierregobin at free dot fr
-Status: Feedback +Status: Closed
 [2011-01-07 18:10 UTC] pierregobin at free dot fr
yes this is related to selinux : disabling selinux makes it work correctly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC