从Apache运行的PHP无法写入文件系统
当从ApacheWebServer运行时,我不能让PHP将文件写入文件系统 我有一个简单的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
<?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