1. 程式人生 > >將PHP錯誤輸入到日誌文件中

將PHP錯誤輸入到日誌文件中

error_log ack rep repo 輸入 error 位置 代碼 顯示錯誤

(LAMP)禁止客戶端瀏覽器顯示PHP代碼錯誤,將錯誤信息保存到日誌文件中:
在php配置文件中找到php.ini(如在Centos6.7下的/etc/php.ini中),設置
  display_errors = Off //不允許在瀏覽器中顯示錯誤信息
  log_errors = On //將錯誤信息輸入到log文件中
  error_log = /var/www/html/php_errors_log//指定錯誤日誌位置
找到apache的配置文件http.conf(如在Centos6.7下的/etc/httpd/conf/httpd.conf),設置
  php_flag display_errors off
  php_value error_reporting 2039
重啟apache服務器
service httpd restart
註:
1、若log_errors指定的目錄存在或沒有權限,錯誤還是會輸出到瀏覽器上的


2、向log_errors文件寫錯誤日誌的Centos用戶是apache(不是apache服務器,而是Centos的一個用戶),所以要註意apache用戶的權限

將PHP錯誤輸入到日誌文件中