AWS写入权限,httpd 2.4

amazon web services,服务器版本:Apache / 2.4.6(红帽企业Linux)

apache日志报告:

[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 

这里是试图写入当前目录的PHP代码:

 <?php file_put_contents("./test.txt", "Test"); // <=== This cannot write!!! $uid = posix_getuid(); echo "PosixGetUID: " . $uid . "<br/>"; $userinfo = posix_getpwuid($uid); print_r($userinfo); ?> 

目录上的权限:

 # 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 

虚拟主机的httpd.conf:

 DocumentRoot /var/www/html/vraim <Directory /> Require all granted </Directory> 

我做错了什么? 为什么PHP不能写入到Apache所有权的文件夹?

PHP脚本本身输出有关其有效用户ID的以下信息:

 PosixGetUID: 48 Array ( [name] => apache [passwd] => x [uid] => 48 [gid] => 48 [gecos] => Apache [dir] => /usr/share/httpd [shell] => /sbin/nologin ) 

可能来自selinux,试着设置为允许检查:

setenforce宽容

当你从一个地方转移到另一个地方时,可能会发生这种情况。 当你移动它时保留原始的selinux上下文