【问题标题】:PHP glob/scandir and Linux softlinks/permissionsPHP glob/scandir 和 Linux 软链接/权限
【发布时间】:2014-02-17 14:32:07
【问题描述】:

我正在尝试编写一个简单的在线音乐播放器来改进我的编程。

我有一台运行 CentOS 6.5 的服务器,带有一个包含我所有文件的外部硬盘。我将存储分区挂载到/mnt/storage,我的音乐在/mnt/storage/cascornelissen/Muziek,具有以下权限:

drwxrwxr-x 19 cascornelissen ftpusers       4096 Nov  4 14:43 Muziek

然后我有一个简单的 httpd 网络服务器,将项目托管在 /var/www/html/melodi,其中包含指向前面提到的 Muziek 目录的软链接:

lrwxrwxrwx 1 root           ftpusers   34 Jan 26 22:31 music -> /mnt/storage/cascornelissen/Muziek

我想使用 PHP 的 glob 列出所有文件,但返回一个空数组。所以我尝试了scandir("music"),但它返回以下错误:

Warning: scandir(music): failed to open dir: Permission denied in /var/www/html/melodi/index.php on line 42

关于如何解决此权限问题的任何想法?

【问题讨论】:

  • 你使用了符号链接吗?
  • 对不起,你到底是什么意思?

标签: php apache permissions symlink


【解决方案1】:

试试这个:

chmod ugo+x /mnt /mnt/storage /mnt/storage/cascornelissen

您的路径的某些部分可能不允许您的 Apache 用户进入。允许进入目录意味着将xexecute permissions添加到目录中。

说明

# create path a/b
mkdir -p a/b
ls a/b          # this works

# now remove all permissions for a
chmod 000 a
ls a/b          # ls: cannot access a/b: Permission denied
                # but why, we should still have permission for b??
                # Now, lets add x permission for a:
chmod ugo+x a
ls a/b          # works again
ls a            # ls: cannot open directory a: Permission denied
                # So, we cannot list contents of a, but we can
                # access a/b *through* a

所以,execute permissionx 表示 目录 意味着我们可以访问它下面的路径,即使我们无法读取目录本身的内容。在您的情况下,Apache 需要“遍历” /mnt/storage/cascornelissen 的权限,即使它在到达 Muziek 之前不会读取任何文件。

【讨论】:

  • 太棒了,成功了!你介意更深入地解释一下吗? apache 是否需要 /Muziek 的每个父级的执行权限?
  • 将在回答中添加解释
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-22
  • 2016-11-15
  • 1970-01-01
  • 2012-12-17
  • 2017-12-29
  • 2011-08-07
  • 2015-10-23
相关资源
最近更新 更多