【发布时间】:2014-04-29 10:34:08
【问题描述】:
我有一个使用 propel 的网站。我想把各种配置文件放在web根目录之外,但是propel需要它们(例如schema.xml、build.properties等)在同一个目录中。因此,我决定将 Web 根目录中的符号链接添加到这些目录:
somesite.com/
|
|- public/
| |- index.php
| |- build -> ../private/build
| |- vendor -> ../private/vendor
|
|- private/
| |- build.properties
| |- schema.xml
| |- build/
| |- vendor/
我的包含路径是这样设置的:
set_include_path('vendor/propel/propel1/runtime/lib' . PATH_SEPARATOR . 'build/classes' . PATH_SEPARATOR . get_include_path());
但是,当我尝试require_once 'Propel.php'; 时,我收到以下错误:
Warning: require_once(Propel.php): failed to open stream: No such file or directory in /home/staging/apache/somewebsite.co.uk/public/functions.php on line 5
用chdir('vendor/propel/propel1/runtime/lib');检查我得到以下错误:
Warning: chdir(): Permission denied (errno 13) in /home/staging/apache/somewebsite.co.uk/public/functions.php on line 5
因此,PHP/Apache 似乎不会遵循符号链接。我尝试了以下方法:
- 检查了目录是
o+x,所以apache可以读取它 - 在 apache 配置中的目录指令中添加了
Options FollowSymLinks(尽管在文档中它说这是默认设置) - 我还尝试
chcon -R -h -t httpd_sys_content_t public/vendor/更改 SELinux 类型,但由于某种原因它没有改变
更新
我以 apache 用户 (su -s /bin/bash apache) 身份登录并从 public 目录中运行 cat vendor/propel/propel1/runtime/lib/Propel.php,它运行良好。但是,我暂时禁用了 SELinux,错误消失了。所以当然是 SELinux。
正如我之前提到的,我尝试过:
chcon -R -h -t httpd_sys_content_t public/vendor/
但在这样做之后,运行 ls -alZ 会为供应商提供以下信息:
lrwxrwxrwx. staging developers unconfined_u:object_r:user_home_t:s0 vendor -> /home/staging/apache/somewebsite.co.uk/private/vendor/
有什么想法吗?
【问题讨论】:
-
当您冒充为 Web 服务器用户时,您可以从控制台访问这些文件吗?
-
是的,
su -s /bin/bash apache和cat vendor/propel/propel1/runtime/lib/Propel.php从public目录中可以很好地列出该文件的内容。 -
如果你以 apache 用户的身份执行一个小的 php-cli 脚本会发生什么?
-
从
public目录运行php -r "chdir('vendor');var_dump(getcwd());"输出string(61) "/home/staging/apache/somewebsite.co.uk/private/vendor" -
ok,也就是说只有使用apache sapi才会出现问题?
标签: php centos symlink selinux