gpt4 book ai didi

php - fopen() : failed to open stream: Permission denied (when path permission is 777)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:57 27 4
gpt4 key购买 nike

<分区>

[Duplicated]

PHP函数fopen()在所有路径都是777权限时出现权限错误。
服务器详细信息:Centos 7、PHP 7.1.8、Apache 2.4.27

PHP 源代码:

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

错误信息:

Warning: fopen(newfile.txt): failed to open stream: Permission denied in /var/www/html/test/file.php on line 3

MyTest 网址: http://MyIPAddress/test/file.php

777 条权限路径:

/var/www  
/var/www/html
/var/www/html/test
/var/www/html/test/file.php

具有权限的文件列表: (编辑 1)

[root@localhost ~]# ls -la /var/www/html/test
total 8
drwxrwxrwx. 2 root root 41 Aug 24 20:26 .
drwxrwxrwx. 4 root root 48 Aug 24 19:37 ..
-rwxrwxrwx. 1 root root 179 Aug 24 20:22 file.php
-rwxrwxrwx. 1 root root 1 Aug 24 20:22 newfile.txt

SELinux 已启用并具有访问列表:

[root@localhost ~]# semanage fcontext -l |grep "var/www"
/var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/html(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/html/(.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0

(Edit2)*:如果我禁用 SELinux,问题就会解决,问题来自 SELinux,我会提出一个新问题,为什么当我也有访问列表时出错.

27 4 0