Apache 对 html 文件夹没有写权限

Apache does not have write permission on html folder

我在 CentOS 7 中安装了 apacheMySQLPHP。一切正常,除了 apache 无法写入 html 文件夹中的文件。我在使用file_put_contents的时候发现了这个问题。我试过了

  1. /var/wwwowner 更改为 apache:apache,不起作用
  2. httpd.conf中添加Order allow,denyAllow from all<Directory "/var/www/html">,重启httpd服务,不工作
  3. chmod -R 0777 /var/www/html,没用

我的服务器出了什么问题?请帮助我!

UPDATE1:ls -al /var/www/html

的结果
total 40
drwxrwxrwx.  5 apache apache 4096 Sep 23 10:19 .
drwxr-x---.  4 apache apache   31 Sep 18 01:50 ..
drwxrwxrwx. 15 apache apache 4096 Sep 23 08:43 folder1
drwxrwxrwx+ 10 apache apache 4096 Sep 23 10:19 folder2
-rwxrwxrwx.  1 apache apache 1574 Sep  5 08:55 favicon.ico
-rwxrwxrwx.  1 apache apache  603 Sep 22 05:05 .htaccess
-rwxrwxrwx.  1 apache apache 9841 Sep  8 08:34 index.php
drwxrwxrwx.  8 apache apache 4096 Sep 23 08:44 folder3

更新 2:apache error_log(我更改了所有 IP 地址)- 编辑,更改为新的 error_log,停止 httpd,备份 error_log,启动 httpd

[Thu Sep 24 07:06:47.540295 2015] [core:notice] [pid 14439] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Thu Sep 24 07:06:47.541787 2015] [suexec:notice] [pid 14439] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Sep 24 07:06:47.569389 2015] [so:warn] [pid 14439] AH01574: module rewrite_module is already loaded, skipping
[Thu Sep 24 07:06:47.572287 2015] [auth_digest:notice] [pid 14439] AH01757: generating secret for digest authentication ...
[Thu Sep 24 07:06:47.573315 2015] [lbmethod_heartbeat:notice] [pid 14439] AH02282: No slotmem from mod_heartmonitor
[Thu Sep 24 07:06:47.600913 2015] [mpm_prefork:notice] [pid 14439] AH00163: Apache/2.4.6 (CentOS) PHP/5.4.16 configured -- resuming normal operations
[Thu Sep 24 07:06:47.600943 2015] [core:notice] [pid 14439] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

a.txt 文件的权限问题

警告:file_put_contents(a.txt):无法打开流:第 2

行 /var/www/html/index.php 中的权限被拒绝

谢谢大家!我用本指南解决了我的问题:

http://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

希望对您有所帮助。

如果您使用的是 Centos SELinux,要允许向 apache 用户写入特定目录,请使用以下命令。确保将 /var/www/html/logs 更改为您需要写入的任何目录。

$ chcon -t httpd_sys_rw_content_t /var/www/html/logs/ -R

来源:https://www.svnlabs.com/blogs/centos-7-selinux-apache-php-writeaccess-permission/