Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Apache运行的PHP无法写入文件系统_Php_Apache_Amazon Web Services - Fatal编程技术网

从Apache运行的PHP无法写入文件系统

从Apache运行的PHP无法写入文件系统,php,apache,amazon-web-services,Php,Apache,Amazon Web Services,当从ApacheWebServer运行时,我不能让PHP将文件写入文件系统 我有一个简单的PHP脚本: <?php print 'User : '.posix_getpwuid(posix_getuid())['name']; print ' '; print 'Group: '.posix_getgrgid(posix_getgid())['name']; file_put_contents('./test.txt', 'OK'); ?> 该脚本位于Apache文档根目录中 /v

当从ApacheWebServer运行时,我不能让PHP将文件写入文件系统

我有一个简单的PHP脚本:

<?php
print 'User : '.posix_getpwuid(posix_getuid())['name'];
print ' ';
print 'Group: '.posix_getgrgid(posix_getgid())['name'];
file_put_contents('./test.txt', 'OK');
?>
该脚本位于Apache文档根目录中

/var/www/html/test.php

drwxr-xr-x.  21 root root 4096 ene 31 05:45 var
drwxrwsr-x.  4 root www    31 ene 29 17:30 www
drwxrwsr-x. 2 root www 36 ene 31 06:16 html
-rw-rw-r--. 1 ec2-user www 172 ene 31 06:15 test.php
如果在PHP cli中运行脚本,将创建文件
test.txt
,并生成以下输出

>php ./test.php
User : ec2-user Group: ec2-user
但是,如果通过浏览器将脚本作为普通网页或通过curl调用,则会出现文件权限错误:

> curl http://my.ip/test.php
User : ec2-user Group: ec2-user<br />
<b>Warning</b>:  file_put_contents(./test.txt): failed to open stream:     Permission denied in <b>/var/www/html/test.php</b> on line <b>5</b><br />
我已经检查了PHP配置,没有配置
open\u basedir
选项

我尝试使用
777
权限和相同的输出写入
/dummy
文件夹


是否缺少任何配置?

检查selinux是否已启用

selinuxenabled && echo enabled || echo disabled
如果已启用,请尝试禁用

echo 0 > /selinux/enforce

我没有解决方案,但我假设你在AWS上,所以别忘了在你的问题中添加
AWS
标记。这跟那有点关系,就是这样。谢谢您还可以使用
getenforce
检查SeLinux状态。我在
/etc/SELINUX/config
中禁用了编辑
SELINUX=disabled
,然后重新启动。
selinuxenabled && echo enabled || echo disabled
echo 0 > /selinux/enforce