【发布时间】:2018-02-02 13:45:00
【问题描述】:
[重复]
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!");
错误信息:
警告:fopen(newfile.txt):打开流失败:第 3 行 /var/www/html/test/file.php 中的权限被拒绝
我的测试网址: 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,我将提出一个新问题,即为什么我也有访问列表时出现错误.
【问题讨论】:
-
你能不能试着放一个绝对路径而不是相对路径来测试它是否适用于绝对路径。
-
@Kimberlee ,
Warning: fopen(/var/www/html/test/newfile.txt): failed to open stream: Permission denied -
你有在目录中创建的txt文件吗?如果没有,也许你可以尝试创建 txt 文件并再次尝试 fopen..
-
@Kimberlee 和第一个一样 :)
-
如果文件已经创建,文件的权限是什么?
标签: php linux permissions chmod