15,020
edits
(→檔案操作有關) |
|||
| Line 8: | Line 8: | ||
* 檢查該檔案所在目錄是否已經建立,若未建立則需要建立 [http://php.net/manual/en/function.mkdir.php mkdir],並設定可以寫入。如果產生位置是在多層子目錄下 (巢狀的多層目錄),則需要啟用 recursive 選項<ref>[http://stackoverflow.com/questions/2303372/create-a-folder-if-it-doesnt-already-exist php - Create a folder if it doesn't already exist - Stack Overflow] code snippet: <nowiki>mkdir('path/to/directory', 0755, true);</nowiki> </ref> | * 檢查該檔案所在目錄是否已經建立,若未建立則需要建立 [http://php.net/manual/en/function.mkdir.php mkdir],並設定可以寫入。如果產生位置是在多層子目錄下 (巢狀的多層目錄),則需要啟用 recursive 選項<ref>[http://stackoverflow.com/questions/2303372/create-a-folder-if-it-doesnt-already-exist php - Create a folder if it doesn't already exist - Stack Overflow] code snippet: <nowiki>mkdir('path/to/directory', 0755, true);</nowiki> </ref> | ||
* 設定該檔案/目錄是否可以寫入: 如果要刪除或寫入檔案,需要檢查是否具備寫入權限 | * 設定該檔案/目錄是否可以寫入: 如果要刪除或寫入檔案,需要檢查是否具備寫入權限 | ||
*# SELinux (Security-Enhanced Linux) policy: {{kbd | key = httpd_sys_rw_content_t}}<ref>[https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/ CentOS 7 + SELinux + PHP + Apache – cannot write/access file no matter what | Lysender's Daily Log Book]</ref> | *# SELinux (Security-Enhanced Linux) policy: {{kbd | key = httpd_sys_rw_content_t}}<ref>[https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/ CentOS 7 + SELinux + PHP + Apache – cannot write/access file no matter what | Lysender's Daily Log Book]</ref> | ||
*# (optional) 該檔案/目錄的 (1) 擁有者是網站使用者 (e.g. 網站伺服器設定檔預設值 CentOS 是 apache、Ubuntu 則是 www-data<ref>[https://ubuntuforums.org/showthread.php?t=1293508 [SOLVED] How to find out Apache Username?]</ref>) 、或者是 (2) 網站使用者的群組 (e.g. CentOS 是 apache) 可以寫入 | |||
* 驗證是否具備寫入權限: | * 驗證是否具備寫入權限: | ||
*# 輸入 {{Linux}} 指令 (1) 檢查檔案權限 {{kbd | key = ls -Z /path/to/file}}、(2) 檢查目錄權限 {{kbd | key = ls -Zd /path/to/directory/}} | *# 輸入 {{Linux}} 指令 (1) 檢查檔案權限 {{kbd | key = ls -Z /path/to/file}}、(2) 檢查目錄權限 {{kbd | key = ls -Zd /path/to/directory/}} | ||