>  기사  >  백엔드 개발  >  centos7 - 이상한 PHP 파일 읽기 및 쓰기 권한 문제 [모두 777+apache:apache]?

centos7 - 이상한 PHP 파일 읽기 및 쓰기 권한 문제 [모두 777+apache:apache]?

WBOY
WBOY원래의
2016-12-01 00:56:432411검색

언급한 대로 현재 웹사이트 디렉토리는 /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에서 사용자와 그룹을 살펴보니 Apache에는 아무런 문제가 없었습니다.
그런데 json 파일이 캐시 폴더에 기록되지 않고 $myfile이 항상 false를 반환했습니다.
이 문제가 무엇인지 알려주세요. 더블 일레븐 센토스 토론방에 댓글이 가득하고 무슨 일인지 모르겠습니다...
긴급요청... ......(무력

답글 내용:

언급한 대로 현재 웹사이트 디렉토리는 /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에서 사용자와 그룹을 살펴보니 Apache에는 아무런 문제가 없었습니다.
그런데 json 파일이 캐시 폴더에 기록되지 않고 $myfile이 항상 false를 반환했습니다.
이 문제가 무엇인지 알려주세요. 더블 일레븐 센토스 토론방에 댓글이 가득하고 무슨 일인지 모르겠습니다...
긴급요청... ......(무력

SELinux 상태 보기

왜 루트 디렉터리에 써야 하나요? 현재 디렉터리가 작동하지 않나요?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.