[精讚] [會員登入]
25514

[Apache] 顯示或不顯示錯誤

php預設錯誤不顯示,有三種方法可以顯示或不顯示錯誤

分享此文連結 //n.sfs.tw/10420

分享連結 [Apache] 顯示或不顯示錯誤@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2022-03-16 00:36:07 最後編修
2016-12-12 12:02:34 By 張○○
 

自動目錄

php預設錯誤不顯示,可修改 /etc/php.ini

; 約513行,顯示全部除了作廢等級
error_reporting = E_ALL & ~E_DEPRECATED
; 約530行,顯示錯誤
display_errors = On
; 約541行,顯示php啟動錯誤
display_startup_errors = Off
; 約 551,記錄錯誤
log_errors = On

但如果沒辦法或沒存取php.ini的權限,例如是共用的伺服器;或是不想影響其他網頁的設定,有兩個方法:

方法一,使用php的ini_set

<?php
ini_set(‘error_reporting’, E_ALL & ~E_DEPRECATED);
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1); 


吃飽了休息一下

方法二,使用 .htaccess 檔

條件是目錄的權限要容許 overwrite

    <Directory "/path/to/your/website">
        AllowOverride All
        ...
    </Directory>

在你的網頁目錄下新增一個.htaccess的檔,內容為

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
# 設定把錯誤記錄
php_flag  log_errors on
php_value error_log  /path/to/your/website/PHP_errors.log
# 防止直接由網頁存取log
<Files PHP_errors.log>
   Order allow,deny
   Deny from all
   Satisfy All
</Files>

參考資料

[1] http://perishablepress.com/press/2007/12/17/how-to-enable-php-err

 

 

END

你可能感興趣的文章

UTF-8的網頁但IE8一片空白 UTF8編碼的網頁在Firefox 正常顯示、但IE8 就是空白,IE8編碼設定是「自動偵測」可是自動偵測到的是 big5...

PHP 7.0 升級到 PHP7.3 因為套件的關係,想把PHP7.0升到7.3 結果又退回原版本

[Apache] 顯示或不顯示錯誤 php預設錯誤不顯示,有三種方法可以顯示或不顯示錯誤

[APACHE] Centos7,8設定 HSTS ( HTTP Strict Transport Security ) CENTOS7,CENTOS8 資安上需要設定的 HSTS的方法。

[Apache] 利用.htaccess防盜圖 利用.htaccess防盜圖,同時也介紹一個產生防盜圖.htaccess檔的網站

強迫網頁預設編碼語系 大部分的瀏覽器如果編碼設成「自動偵測」時都能正確的分析。但世界並不會這麼平順完美,明明我這樣設定utf8他就是用big5丟出來...

<<此文不開放留言>>

隨機好文

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他

[札記] 2016.7~12月札記 札記,只是札記

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

Smarty安裝 smarty 是著名的樣版引擎,非常的好用,用多了突然發現拿掉smarty反而不會寫php了,以下是安裝過程..

魔球中小女孩唱的歌 The show 魔球中小女孩唱的歌 The show