配置php显示错误

配置php显示错误

 

默认php是不显示错误的,例如你写了

require_once('xxx.php')

但是这个文件并不存在,这样导致你的网页输出不正常,但是你又看不到这个错误,要看到这个错误,就需要打开php的错误显示。这个配置是在php的配置文件 php.ini文件中,在linux系统中,这个文件的位置是在

/etc/php.ini

打开它,找到下面的内容,

 

 515 ; This directive controls whether or not and where PHP will output errors,
 516 ; notices and warnings too. Error output is very useful during development,,
      but
 517 ; it could be very dangerous in production environments. Depending on the cc
     ode
 518 ; which is triggering the error, sensitive information could potentially lee
     ak
 519 ; out of your application such as database usernames and passwords or worsee

 520 ; It's recommended that errors be logged on production servers rather than
 521 ; having the errors sent to STDOUT.
 522 ; Possible Values:
 523 ;   Off = Do not display any errors
 524 ;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
 525 ;   On or stdout = Display errors to STDOUT
 526 ; Default Value: On
 527 ; Development Value: On
 528 ; Production Value: Off
 529 ; http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-erroo
     rs
 530 display_errors = Off

看到530了吧,默认是off,我们把它的值改为 On

然后保存退出即可。

上面也提到了,在开发阶段,建议将它的值设为On,发布之后改为Off。

 

上面说到是怎么显示错误,其实php还有一个参数用来控制到底输出什么样的错误,这个通过

error_reporting

这个参数控制。

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; error_reporting is a bit-field.  Or each number up to get desired error
; reporting level
; E_ALL             - All errors and warnings (doesn't include E_STRICT)
; E_ERROR           - fatal run-time errors
; E_WARNING         - run-time warnings (non-fatal errors)
; E_PARSE           - compile-time parse errors
; E_NOTICE          - run-time notices (these are warnings which often result
;                     from a bug in your code, but it's possible that it was
;                     intentional (e.g., using an uninitialized variable and
;                     relying on the fact it's automatically initialized to an
;                     empty string)
; E_STRICT          - run-time notices, enable to have PHP suggest changes
;                     to your code which will ensure the best interoperability
;                     and forward compatibility of your code
; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
;                     initial startup
; E_COMPILE_ERROR   - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR      - user-generated error message
; E_USER_WARNING    - user-generated warning message
; E_USER_NOTICE     - user-generated notice message
;
; Examples:
;
;   - Show all errors, except for notices and coding standards warnings
;
;error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
;
;   - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE
;
;   - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
;   - Show all errors
;
error_reporting  =  E_ALL

默认是输出所有的错误,可以根据自己的需求,自定义。

 

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章转载自:IT夜班车,否则按侵权处理.

    分享到:

Leave a Reply

Your email address will not be published. Required fields are marked *