访问文档根目录外的文件

我试图写在文件根目录之外的文件是/var/www/html 。 我想要访问的文件是/home/user/files/folder1/info.txt ,但我的PHP文件无法打开它(甚至说它不存在,我用file_exists检查它)。 我尝试recursion地chown文件夹/home/user/fileschown -R apache /home/user/files ),同时我也设置了对info.txt文件的权限777,但似乎没有任何效果。

我在CentOS和Apache2上。

httpd_selinux(8)手册页:

  SELinux policy for httpd can be setup to not allowed to access users home directories. If you want to allow access to users home directo- ries you need to set the httpd_enable_homedirs boolean and change the context of the files that you want people to access off the home dir. setsebool -P httpd_enable_homedirs 1 chcon -R -t httpd_sys_content_t ~user/public_html 

这是一个远射,但是你的php可能已经在php.ini文件中被强化了。 在你的php.ini文件中find类似open_basedir = /path/to/web/root

open_basedir将所有PHP文件操作限制在列出的目录和下面。

虽然我不熟悉selinux,所以其他的海报可能会在正确的轨道上,但这也可能有帮助:

  • 从文件创build一个符号链接到/var/www/html/目录
  • 确保FollowSymLinks选项已打开 – 您可以在主httpd.conf或在/var/www/html中的.htaccess中使用以下行进行此操作: Options FollowSymLinks