【发布时间】:2012-08-31 22:23:33
【问题描述】:
所以,我有这个错误:
Warning: fopen(/path/to/test-in.txt) [function.fopen]: failed to open stream: Permission denied
在test-in.txt所在的目录中执行ls -l会产生以下输出:
-rw-r--r-- 1 $USER $USER 1921 Sep 6 20:09 test-in.txt
-rw-r--r-- 1 $USER $USER 0 Sep 6 20:08 test-out.txt
为了解决这个问题,我决定执行以下操作:
chgrp -R www-data /path/to/php/webroot
然后做了:
chmod g+rw /path/to/php/webroot
然而,当我运行 php5 脚本打开文件时,我仍然收到此错误。为什么会这样?我已经通过 CGI 使用 LAMP 和 cherokee 尝试过这个,所以不可能是这样。
有什么解决办法吗?
编辑
我还要补充一点,我现在只是通过 localhost 进行开发。
更新 - PHP fopen() 行
$fullpath = $this->fileRoot . $this->fileInData['fileName'];
$file_ptr = fopen( $fullpath, 'r+' );
我还应该提到,如果可能的话,我想坚持使用 Cherokee。为 Apache/Cherokee 设置文件权限有什么用?
【问题讨论】:
-
网络服务器是以什么用户身份运行的,是否有打开文件的权限?
-
它以我的用户身份运行。至于第二个,我可以
cat文本文件没有任何错误,如果有帮助的话。 -
你确定 - 端口 80 是一个特权端口,我怀疑你可以打开它。请同时添加 PHP 行
-
你能写下真实文件路径上每个目录的权限吗?
-
更改权限即可。在 linux 主机中右键单击该文件,然后单击更改权限。然后启用所有权限。
标签: php linux permissions io fopen