Maison  >  Article  >  développement back-end  >  centos7 - 奇怪的php文件读写权限问题【全777+apache:apache】?

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

WBOY
WBOYoriginal
2016-12-01 00:56:432411parcourir

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

<code>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;
}

</code>

function.php

<code>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);
}</code>

这是我ls -l的部分结果

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

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

回复内容:

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

<code>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;
}

</code>

function.php

<code>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);
}</code>

这是我ls -l的部分结果

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

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

查看SELinux状态

为啥非要写到根目录 当前目录不行么

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn