I'm trying to write on a file that is outside the document root, which is /var/www/html. The file I want to access is /home/user/files/folder1/info.txt, but my PHP file can't open it (it does even say that it doesn't exist, I checked it with file_exists). I tried to chown the folder /home/user/files recursively (chown -R apache /home/user/files) and I also set the permissions to 777 on the info.txt file, but nothing seems to work.

I'm on CentOS and Apache2.

link|improve this question
feedback

3 Answers

From the httpd_selinux(8) man page:

   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
link|improve this answer
feedback

While I'm not familiar with selinux, so the other poster may be on the right track, but this might help, too:

  • Create a symlink from the file to the /var/www/html/ directory
  • Make sure The option FollowSymLinks is on -- you can do this in the main httpd.conf or in .htaccess in /var/www/html with this line: Options FollowSymLinks
link|improve this answer
feedback

This is a long shot, but your php might have been hardened within the php.ini file. Look in your php.ini file for something like open_basedir = /path/to/web/root.

open_basedir limits all PHP file operations to the listed directory and below.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.