Amazon Web Services, Server version: Apache/2.4.6 (Red Hat Enterprise Linux)
The apache log reports:
[Fri Aug 07 13:53:40.793562 2015] [:error] [pid 10730] [client 149.88.114.40:40800] PHP Warning: file_put_contents(./test.txt): failed to open stream: Permission denied in /var/www/html/vraim/index.php on line 18
Here is PHP code which tries to write to the current directory:
<?php
file_put_contents("./test.txt", "Test"); // <=== This cannot write!!!
$uid = posix_getuid();
echo "PosixGetUID: " . $uid . "<br/>";
$userinfo = posix_getpwuid($uid);
print_r($userinfo);
?>
The permissions on the directory:
# namei -movl /var/www/html/vraim/
f: /var/www/html/vraim/
dr-xr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x apache root html
drwxrwxrwx apache root vraim
The httpd.conf for the virtual host:
DocumentRoot /var/www/html/vraim
<Directory />
Require all granted
</Directory>
What do I do wrong? Why PHP cannot write to the folder which is in ownership of Apache?
PHP script itself outputs the following info about its effective user id:
PosixGetUID: 48
Array ( [name] => apache [passwd] => x [uid] => 48 [gid] => 48 [gecos] => Apache [dir] => /usr/share/httpd [shell] => /sbin/nologin )
could come from selinux, try to set it to permissive to check:
this could happen when you mv something from one place to another. It preserves the selinux context of the original when you move it