linux - chmod命令之後安裝php應用提示檔案依然不可寫

來源:互聯網
上載者:User
我想要在自己的Linux系統下安裝一些開源的php應用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然後對freechat下的data檔案夾中的public和private檔案夾使用了 chmod 777命令,然後使用 ls -al data命令可以看到這樣的結果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在瀏覽器裡輸入http://localhost/freechat 卻會得到這樣的錯誤:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

還嘗試過用遞迴的chmod命令,錯誤依舊。

利用代碼


發現使用者名稱是apache,然後在/etc/httpd/conf/httpd.conf裡發現User和Group都是apache。請問之所以顯示檔案不可寫是因為這個使用者的設定問題嗎?如果是的話我該怎麼修改?如果不是的話又是什麼問題導致的呢?

回複內容:

我想要在自己的Linux系統下安裝一些開源的php應用,譬如phpFreeChat,我把它放在/var/www/html/freechat底下,然後對freechat下的data檔案夾中的public和private檔案夾使用了chmod 777命令,然後使用ls -al data命令可以看到這樣的結果:

drwxr-xr-x. 4 root root 4096 Jun 17 15:07 .
drwxr-xr-x. 13 root root 4096 Jun 17 15:22 ..
drwxrwxrwx. 2 root root 4096 Jun 17 15:07 private
drwxrwxrwx. 3 root root 4096 Jun 17 15:07 public

但是在瀏覽器裡輸入http://localhost/freechat 卻會得到這樣的錯誤:

phpFreeChat cannot be initialized, please correct these errors:

/var/www/html/freechat/src/../data/private is not writeable
/var/www/html/freechat/src/../data/private/cache can't be created
/var/www/html/freechat/src/../data/private/cache is not writeable
/var/www/html/freechat/src/../data/private/cache is not readable
cannot create /var/www/html/freechat/src/../data/public/themes/default
cannot create /var/www/html/freechat/src/../data/public/themes/default
/var/www/html/freechat/src/../data/private/chat can't be created
/var/www/html/freechat/src/../data/private/chat is not writeable
/var/www/html/freechat/src/../data/private/chat is not readable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada can't be created
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not writeable
/var/www/html/freechat/src/../data/private/chat/s_d0ba868e1391b6c0d897996049a68ada is not readable

還嘗試過用遞迴的chmod命令,錯誤依舊。

利用代碼


發現使用者名稱是apache,然後在/etc/httpd/conf/httpd.conf裡發現User和Group都是apache。請問之所以顯示檔案不可寫是因為這個使用者的設定問題嗎?如果是的話我該怎麼修改?如果不是的話又是什麼問題導致的呢?

問題解決了,竟然是SELinux從中作梗。使用setenforce 0以後便成功了。

應該是這個原因,你用chown -rf apache.apache /var/www/html/freechat/data/試試

chmod 777 -R /var/www/html/freechat/data

遞迴修改許可權
或者向 @joyqi 說的把目錄owner改成apache

chown -R apache:apache /var/www/html/freechat

Rpm系一定要記得setenforce 0,暫時關閉selinux後再測試

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.