尽管使用PHP具有适当的权限,但权限被拒绝 [英] Permission denied despite appropriate permissions using PHP

查看:102
本文介绍了尽管使用PHP具有适当的权限,但权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用PHP读取文件,但出现了权限被拒绝的错误,尽管每个人都对该文件具有读取权限.

I'm trying to read a file in PHP and I'm getting a permission denied error although everybody has read access to the file.

PHP代码:

$config=file_get_contents('/opt/jenkins/home/config.xml');

错误:

Warning: file_get_contents(/opt/jenkins/home/config.xml): failed to open stream: Permission denied in [...]

文件系统权限:

有一个将/opt/jenkins/home/指向/var/lib/jenkins的符号链接,每个人都具有对该符号链接,实际文件夹和文件的读取权限.

There is a symlink pointing /opt/jenkins/home/ to /var/lib/jenkins and everybody has read permission on the symlink, actual folder, and file.

$ ls -lh /opt/jenkins/
lrwxrwxrwx 1 sysadmin sysadmin   16 2011-08-04 08:12 home -> /var/lib/jenkins

$ ls -lh /var/lib/ | grep jenkins
drwxr-xr-- 6 jenkins adm     4.0K 2011-08-04 10:04 jenkins

$ ls -lh /var/lib/jenkins/config.xml
-rwxr-xr-- 1 jenkins adm 3.9K 2011-08-04 10:05 /var/lib/jenkins/config.xml

Apache配置

配置为遵循符号链接(Options All).为/var/lib/jenkins/添加Directory指令没有区别.

Configured to folllow symlinks (Options All). Adding a Directory directive for /var/lib/jenkins/ makes no difference.

<Directory /opt/jenkins/home/>
        Options All
        AllowOverride All
        Order Allow,Deny
        Allow from All
</Directory>

其他信息

我是否使用通过符号链接("/opt/jenkins/home/config.xml")或真实路径("/var/lib/jenkins/config.xml")的路径,都遇到相同的问题.

Whether I use the path through the symlink ("/opt/jenkins/home/config.xml") or the real path ("/var/lib/jenkins/config.xml") I have the same problem.

apache2 version=2.2.14-5ubuntu8.4
php version=5.3.2-1ubuntu4.9

关于我为什么收到错误消息的任何想法?

推荐答案

您的目录需要execute权限才能起作用.它似乎没有执行世界,并且由于jenkins可能不是apache用户,并且apache用户不在adm组中,所以它不起作用:

Your directory needs execute permission for this to work. It does not seem to have world execute, and since jenkins is probably not the apache user, and the apache user is not in the adm group, it wouldn't work:

$ ls -lh /var/lib/ | grep jenkins
drwxr-xr-- 6 jenkins adm     4.0K 2011-08-04 10:04 jenkins

每个示例:

netcoder@netcoder:~$ mkdir foo
netcoder@netcoder:~$ echo hello > foo/bar
netcoder@netcoder:~$ chmod 777 foo/bar
netcoder@netcoder:~$ ls -lsah foo/bar 
4.0K -rwxrwxrwx 1 netcoder netcoder 6 2011-08-04 08:22 foo/bar
netcoder@netcoder:~$ chmod 444 foo/
netcoder@netcoder:~$ ls -lsah | grep foo
4.0K dr--r--r--  2 netcoder netcoder 4.0K 2011-08-04 08:22 foo
netcoder@netcoder:~$ cat foo/bar 
cat: foo/bar: Permission denied

即使foo/bar具有0777权限,如果目录没有执行权限,也会拒绝读取其内容.

Even though foo/bar has 0777 permission, if the directory does not have the execute permission, reading its contents is denied.

您需要同时为目标目录和符号链接设置权限.

You'll need the permission to be set for both the target directory and the symbolic link.

这篇关于尽管使用PHP具有适当的权限,但权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆