2014-02-28 70 views
0

代碼(位於/var/www/html/fileio_test/io_test.php):的fopen權限被拒絕Apache服務器

<?php 

$logging = <<< LOG 
This is a test 
LOG; 

$testfile = fopen('/home/djameson/test.txt','a'); // append mode 
fwrite ($testfile, $logging); 
fclose($testfile); 

?> 

的test.txt(在/home/djameson/test.txt):

-rwxrw-r--. 1 apache apache  0 Feb 28 20:21 test.txt 

錯誤:

Warning: fopen(/home/djameson/test.txt): failed to open stream: Permission denied in /var/www/html/fileio_test/io_test.php on line 7 

Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 8 

Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 9 

在此去過許多天左右的文件權限的改變,增加的test.txt到不同的組,但我一直沒能寫入文件。有任何想法嗎?

sestatus的結果:

SELinux status:     enabled 
SELinuxfs mount:    /sys/fs/selinux 
SELinux root directory:   /etc/selinux 
Loaded policy name:    targeted 
Current mode:     permissive 
Mode from config file:   enforcing 
Policy MLS status:    enabled 
Policy deny_unknown status:  allowed 
Max kernel policy version:  28 

其它信息:

服務器上的fedora 20運行; 位於/ var/www的apache服務器

+0

經常遇到此錯誤,並快速排除故障,請按照下列步驟操作:https://stackoverflow.com/a/36577021/2873507 –

回答

0

很可能selinux正在執行其規則。 從Selinux's wiki on fedoraproject

httpd默認不允許訪問用戶主目錄。
如果您想要允許訪問用戶主目錄,您需要設置 httpd_enable_homedirs布爾值,並更改您希望人們訪問的文件的上下文( )離開主目錄。

因此,應該嘗試暫時禁用了SELinux - >setenforce 0WARN:這將完全禁用了SELinux您的系統上當前會話請不要執行本在生產服務器上)。如果在此之後它工作可能是正在執行的sebool httpd_enable_homedirs。如果你想完全禁用了SELinux禁用只是標誌,而不是你可以運行:

setsebool httpd_enable_homedirs 1 //This will enable for the current session only 

,如果你想永久設置:

setsebool -P httpd_enable_homedirs 1 //Permanent 

設置之後,你應該運行chcon這個或的restorecon上用戶主目錄:

chcon -R -t httpd_sys_content_t /home/djameson 
+0

冉命令setenforce 0,沒有效果。然後,我運行setsebool httpd_enable_homedirs 1和chcon -R -t httpd_sys_content_t/home/djameson。這些命令都不幸有任何效果。我重新啓動sudo服務httpd重新啓動只是爲了確保。 – user3247608

+0

你可以發佈getsebool -a |的結果嗎? grep httpd? –

+0

現在,此處有一個常見錯誤的故障排除清單:https://stackoverflow.com/a/36577021/2873507 –

0

安東尼奧的職位是我的想法。你可能會檢查的一件事是,apache實際上可以訪問/home/djameson(chmod + x是你的朋友)。