centos7 - 奇怪的php文件读写权限问题【全777+apache:apache】?

查看:327
本文介绍了centos7 - 奇怪的php文件读写权限问题【全777+apache:apache】?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如题,我当前的网站目录是/var/www/html(777权限)
然后我的
/var/www/html/g/data/visit.php 文件

require("../function.php");
if (file_exists($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json")) {
    echo file_get_contents($_SERVER["DOCUMENT_ROOT"]. "/cache/vc-$date.json");
} else {
    $res=get_sum();
    $days1=get_days(1);
    $month=get_this_month();

    $result=["visit"=>$res,'days'=>$days1,'month'=>$month];
    $echo = json_encode($result);
    cache_this($echo,'vc-'.$date);
    echo $echo;
}

function.php

function cache_this($result,$name){//内容,命名规则
  //file_put_contents("/cache/$name.json", $result)or die("Unable to open file!");

    $myfile = fopen($_SERVER['DOCUMENT_ROOT']."/cache/$name.json", "w") or die("Unable to open file!");
    $txt = $result;
    fwrite($myfile, $txt);
    fclose($myfile);
}

这是我ls -l的部分结果

-rwxrwxrwx.  1 root   root        81 11月  4 2013 bottom.php
drwxrwxrwx.  2 apache apache    4096 11月 10 17:09 cache

然后我看了httpd.conf里面的user和group,都是apache没有错
但是这个json文件就是写不进cache文件夹里面,$myfile总是返回false。
求教这个是什么问题,已经折腾了一晚上,双十一centos讨论群里面都在水,也没问出个究竟……
急求…………………………(无力

解决方案

查看SELinux状态

这篇关于centos7 - 奇怪的php文件读写权限问题【全777+apache:apache】?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆