0
PHP函數fopen()
得到許可錯誤時,所有的路徑是與777的權限。
服務器的詳細信息:Centos 7 , PHP 7.1.8 , Apache 2.4.27
PHP源代碼:
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
錯誤消息:
警告:FOPEN(newfile.txt):未能打開流:權限被拒絕in line 3上的/var/www/html/test/file.php
MyTest的地址:http://MyIPAddress/test/file.php
777許可的路徑:
/var/www
/var/www/html
/var/www/html/test
/var/www/html/test/file.php
文件列表與權限:(編輯1)
[[email protected] ~]# ls -la /var/www/html/test
total 8
drwxrwxrwx. 2 root root 41 Aug 24 20:26 .
drwxrwxrwx. 4 root root 48 Aug 24 19:37 ..
-rwxrwxrwx. 1 root root 179 Aug 24 20:22 file.php
-rwxrwxrwx. 1 root root 1 Aug 24 20:22 newfile.txt
SELinux的啓用&訪問列表:
[[email protected] ~]# semanage fcontext -l |grep "var/www"
/var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/html(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/html/(.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
(EDIT 2)*:如果我禁用SELinux問題就會解決,問題是從SELinux的,我會做一個關於它的新課題那爲什麼我有訪問列表時也會出錯。
你可以嘗試把絕對路徑,而不是相對路徑只是爲了測試它是否適用於絕對。 –
@金伯利,'警告:fopen(/var/www/html/test/newfile.txt):未能打開流:權限被拒絕 – Root125
你有在目錄中創建的txt文件嗎?如果沒有,也許你可以嘗試創建txt文件,然後再次嘗試fopen。 –