PHP要求即使在文件+;目录

PHP要求即使在文件+;目录,php,apache,permissions,filesystems,Php,Apache,Permissions,Filesystems,当组和用户设置正确时,我从来没有遇到过PHP能够读取文件的问题 Apache在www数据用户下运行,因此我使用777 chmod将所有内容(组和用户权限)都设置为www数据,但仍然没有任何功能 不知道发生了什么事 PHP未处于安全模式 代码: 文件系统: $ pwd /root/app/class $ ls -la total 76 drwxrwxrwx 2 www-data www-data 4096 Oct 8 10:59 . drwxrwxrwx 9 www-data www-data

当组和用户设置正确时,我从来没有遇到过PHP能够读取文件的问题

Apache在www数据用户下运行,因此我使用777 chmod将所有内容(组和用户权限)都设置为www数据,但仍然没有任何功能

不知道发生了什么事

PHP未处于安全模式

代码:

文件系统:

$ pwd
/root/app/class
$ ls -la
total 76
drwxrwxrwx 2 www-data www-data  4096 Oct  8 10:59 .
drwxrwxrwx 9 www-data www-data  4096 Sep 25 21:25 ..
-rw-r--r-- 1 root     root     26896 Jan 13  2014 something_else.php
-rw-rw-r-- 1 root     root     32807 Mar 11  2015 something.php
-rwxrwxrwx 1 www-data www-data  3439 Mar  3  2015 api.php
错误:

Warning: require(/root/app/class/api.php): failed to open stream: Permission denied in /var/www/website.com/htdocs/app_frontend/include/config.php on line 36

Fatal error: require(): Failed opening required '/root/app/class/api.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/website.com/htdocs/app_frontend/include/config.php on line 36
已尝试调试:

error_reporting(E_ALL);
ini_set('display_errors','On');

$file = '/root/app/class/api.php';

echo sprintf ( '%o', fileperms ( $file ) ), PHP_EOL;
echo posix_getpwuid ( fileowner ( $file ) ), PHP_EOL; // Get Owner
echo posix_getpwuid ( posix_getuid () ), PHP_EOL; // Get User

if (is_file ( $file )) {
    echo "is_file", PHP_EOL;
    ;
}

if (is_readable ( $file )) {
    echo "is_readable", PHP_EOL;
    ;
}

if (is_writable ( $file )) {
    echo "is_readable", PHP_EOL;
}

fopen ( $file, "w" );
结果:

Warning: fileperms(): stat failed for /root/app/class/api.php in /var/www/website.com/...

Warning: fileowner(): stat failed for /root/app/class/api.php in /var/www/website.com/...
编辑:我的服务器上没有启用SElinux,这是apachectl DUMP_模块的输出

$ /usr/sbin/apachectl -t -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
该文件的整个路径需要可读,以便PHP打开它

例如:

# cd /
# ls -al
drwx------ 3 root  wheel  102 jan  1  2014 root
# sudo su
Password:
$ cd /root
$ mkdir pub
$ chmod 777 pub
$ vi pub/test.php

<?php
echo "Hi, world!";
:wq

$ chmod 666 pub/test.php
$ php -a
Interactive shell

php > include "/root/pub/test.php";
Hi, world!
php > exit
$ exit
# php -a
Interactive shell

php > include "/root/pub/test.php";
PHP Warning:  include(/root/pub/test.php): failed to open stream: Permission denied in php shell code on line 1
...
#cd/
#ls-al
drwx------3根轮102 2014年1月1日根
#sudo su
密码:
$cd/根
$mkdir酒吧
$chmod 777酒店
$vi pub/test.php
该文件的整个路径需要可读,以便PHP打开它

例如:

# cd /
# ls -al
drwx------ 3 root  wheel  102 jan  1  2014 root
# sudo su
Password:
$ cd /root
$ mkdir pub
$ chmod 777 pub
$ vi pub/test.php

<?php
echo "Hi, world!";
:wq

$ chmod 666 pub/test.php
$ php -a
Interactive shell

php > include "/root/pub/test.php";
Hi, world!
php > exit
$ exit
# php -a
Interactive shell

php > include "/root/pub/test.php";
PHP Warning:  include(/root/pub/test.php): failed to open stream: Permission denied in php shell code on line 1
...
#cd/
#ls-al
drwx------3根轮102 2014年1月1日根
#sudo su
密码:
$cd/根
$mkdir酒吧
$chmod 777酒店
$vi pub/test.php

禁用SELinux并查看结果。如果是这样,只需安装并运行一个名为SELinux troubleshooter的程序

  • 查找相关警报
  • 单击疑难解答
  • 检查任何列出的插件,并在终端中执行建议的命令

  • 禁用SELinux并查看结果。如果是这样,只需安装并运行一个名为SELinux troubleshooter的程序

  • 查找相关警报
  • 单击疑难解答
  • 检查任何列出的插件,并在终端中执行建议的命令