【发布时间】:2013-08-07 09:52:39
【问题描述】:
我使用的是 Linux 12.04,apache 和 php 安装在上面。我想访问 /root/ 文件夹中的文本文件。我对权限感到非常困惑。我正在使用的 php 脚本
<?php
$file = fopen("/root/cr.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br>";
}
fclose($file);
?>
此脚本能够访问文件 /var/www 文件夹但无法访问 /root/ip.txt 文件。 请帮助并逐步解释。
【问题讨论】:
-
文件权限。
/root/只能由服务器的 root 用户访问。 -
尝试将file.txt的组更改为apache“chown root:apache file.txt”,然后为组提供读写权限。 “chmod g+rw 文件.txt”。现在再试一次。让我知道这是否对您有帮助。
标签: php linux apache permissions apache2