PHP-log: verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 1: Regel 1:
 
== Waar worden log-instellingen geconfigureerd? ==
 
== Waar worden log-instellingen geconfigureerd? ==
  
Het is vaak puzzelen waar PHP-configuraties worden bewaard. Vooral omdat er vaak verschillende sets van configuraties op één en dezelfde computer staan. Ik heb sterk de indruk dat deze instellingen altijd in een ''php.ini''-bestand staan.
+
Het is vaak puzzelen waar PHP-configuraties worden bewaard. Vooral omdat er vaak verschillende sets van configuraties op één en dezelfde computer staan. Ik heb sterk de indruk dat deze instellingen doorgaans in een ''php.ini''-bestand staan. Zie [[PHP-instellingen (hosting)]] voor details.
  
 +
== Wat voor log-instellingen zijn er? ==
  
Waar wordt de locatie van het log bepaald? ==
+
Er zijn in ieder geval twee manieren om de loggerelateerde instellingen te achterhalen:
  
Veel dingen rondom PHP worden geconfigureerd in het ''php.ini''-bestand. Zie
+
=== phpinfo ===
 +
{|
 +
|[[file:20190913-1347.png|thumb|De zekerste manier om loginstellingen te achterhalen, is middels [[Phpinfo()]], omdat je dan zeker weet, dat je de actuele instellingen hebt. Als je in de output zoekt op ''log'', is dit het meest tastbare dat je tegenkomt ⇒ Het is dus het Apache-log]]
 +
|}
  
 +
=== php.ini ===
 +
 +
Een php.ini-bestand bestaat uit een aantal secties. Dit is een voorbeeld van zo'n sectie op m'n laptop. Deze is weinig geoptimaliseerd (sep. 2019):
 +
 +
<pre>
 +
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 +
; Error handling and logging ;
 +
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 +
 +
; This directive informs PHP of which errors, warnings and notices you would like
 +
; it to take action for. The recommended way of setting values for this
 +
; directive is through the use of the error level constants and bitwise
 +
; operators. The error level constants are below here for convenience as well as
 +
; some common settings and their meanings.
 +
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
 +
; those related to E_NOTICE and E_STRICT, which together cover best practices and
 +
; recommended coding standards in PHP. For performance reasons, this is the
 +
; recommend error reporting setting. Your production server shouldn't be wasting
 +
; resources complaining about best practices and coding standards. That's what
 +
; development servers and development settings are for.
 +
; Note: The php.ini-development file has this setting as E_ALL. This
 +
; means it pretty much reports everything which is exactly what you want during
 +
; development and early testing.
 +
;
 +
; Error Level Constants:
 +
; E_ALL            - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
 +
; E_ERROR          - fatal run-time errors
 +
; E_RECOVERABLE_ERROR  - almost 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 is 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
 +
; E_DEPRECATED      - warn about code that will not work in future versions
 +
;                    of PHP
 +
; E_USER_DEPRECATED - user-generated deprecation warnings
 +
;
 +
; Common Values:
 +
;  E_ALL (Show all errors, warnings and notices including coding standards.)
 +
;  E_ALL & ~E_NOTICE  (Show all errors, except for notices)
 +
;  E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)
 +
;  E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)
 +
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
 +
; Development Value: E_ALL
 +
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
 +
; http://php.net/error-reporting
 +
 +
; Strompf
 +
;;;;;;;;;;;;;;;;;;;;;;;;;
 +
;
 +
error_reporting = E_ALL
 +
 +
; This directive controls whether or not and where PHP will output errors,
 +
; notices and warnings too. Error output is very useful during development, but
 +
; it could be very dangerous in production environments. Depending on the code
 +
; which is triggering the error, sensitive information could potentially leak
 +
; out of your application such as database usernames and passwords or worse.
 +
; For production environments, we recommend logging errors rather than
 +
; sending them to STDOUT.
 +
; Possible Values:
 +
;  Off = Do not display any errors
 +
;  stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
 +
;  On or stdout = Display errors to STDOUT
 +
; Default Value: On
 +
; Development Value: On
 +
; Production Value: Off
 +
; http://php.net/display-errors
 +
;display_errors = Off
 +
 +
; strompf
 +
;;;;;;;;;;;;;;;;;;;;;;;;;
 +
;
 +
display_errors = On
 +
 +
; The display of errors which occur during PHP's startup sequence are handled
 +
; separately from display_errors. PHP's default behavior is to suppress those
 +
; errors from clients. Turning the display of startup errors on can be useful in
 +
; debugging configuration problems. We strongly recommend you
 +
; set this to 'off' for production servers.
 +
; Default Value: Off
 +
; Development Value: On
 +
; Production Value: Off
 +
; http://php.net/display-startup-errors
 +
 +
; display_startup_errors = Off
 +
display_startup_errors = On
 +
 +
; Besides displaying errors, PHP can also log errors to locations such as a
 +
; server-specific log, STDERR, or a location specified by the error_log
 +
; directive found below. While errors should not be displayed on productions
 +
; servers they should still be monitored and logging is a great way to do that.
 +
; Default Value: Off
 +
; Development Value: On
 +
; Production Value: On
 +
; http://php.net/log-errors
 +
log_errors = On
 +
 +
; Set maximum length of log_errors. In error_log information about the source is
 +
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
 +
; http://php.net/log-errors-max-len
 +
log_errors_max_len = 1024
 +
 +
; Do not log repeated messages. Repeated errors must occur in same file on same
 +
; line unless ignore_repeated_source is set true.
 +
; http://php.net/ignore-repeated-errors
 +
ignore_repeated_errors = Off
 +
 +
; Ignore source of message when ignoring repeated messages. When this setting
 +
; is On you will not log errors with repeated messages from different files or
 +
; source lines.
 +
; http://php.net/ignore-repeated-source
 +
ignore_repeated_source = Off
 +
 +
; If this parameter is set to Off, then memory leaks will not be shown (on
 +
; stdout or in the log). This has only effect in a debug compile, and if
 +
; error reporting includes E_WARNING in the allowed list
 +
; http://php.net/report-memleaks
 +
report_memleaks = On
 +
 +
; This setting is on by default.
 +
;report_zend_debug = 0
 +
 +
; Store the last error/warning message in $php_errormsg (boolean). Setting this value
 +
; to On can assist in debugging and is appropriate for development servers. It should
 +
; however be disabled on production servers.
 +
; Default Value: Off
 +
; Development Value: On
 +
; Production Value: Off
 +
; http://php.net/track-errors
 +
track_errors = Off
 +
 +
; Turn off normal error reporting and emit XML-RPC error XML
 +
; http://php.net/xmlrpc-errors
 +
;xmlrpc_errors = 0
 +
 +
; An XML-RPC faultCode
 +
;xmlrpc_error_number = 0
 +
 +
; When PHP displays or logs an error, it has the capability of formatting the
 +
; error message as HTML for easier reading. This directive controls whether
 +
; the error message is formatted as HTML or not.
 +
; Note: This directive is hardcoded to Off for the CLI SAPI
 +
; Default Value: On
 +
; Development Value: On
 +
; Production value: On
 +
; http://php.net/html-errors
 +
html_errors = On
 +
 +
; If html_errors is set to On *and* docref_root is not empty, then PHP
 +
; produces clickable error messages that direct to a page describing the error
 +
; or function causing the error in detail.
 +
; You can download a copy of the PHP manual from http://php.net/docs
 +
; and change docref_root to the base URL of your local copy including the
 +
; leading '/'. You must also specify the file extension being used including
 +
; the dot. PHP's default behavior is to leave these settings empty, in which
 +
; case no links to documentation are generated.
 +
; Note: Never use this feature for production boxes.
 +
; http://php.net/docref-root
 +
; Examples
 +
;docref_root = "/phpmanual/"
 +
 +
; http://php.net/docref-ext
 +
;docref_ext = .html
 +
 +
; String to output before an error message. PHP's default behavior is to leave
 +
; this setting blank.
 +
; http://php.net/error-prepend-string
 +
; Example:
 +
;error_prepend_string = "<span style='color: #ff0000'>"
 +
 +
; String to output after an error message. PHP's default behavior is to leave
 +
; this setting blank.
 +
; http://php.net/error-append-string
 +
; Example:
 +
;error_append_string = "</span>"
 +
 +
; Log errors to specified file. PHP's default behavior is to leave this value
 +
; empty.
 +
; http://php.net/error-log
 +
; Example:
 +
;error_log = php_errors.log
 +
; Log errors to syslog (Event Log on Windows).
 +
;error_log = syslog
 +
 +
;windows.show_crt_warning
 +
; Default value: 0
 +
; Development value: 0
 +
; Production value: 0
 +
</pre>
  
 
== Gebruikelijke locatie PHP-log? ==
 
== Gebruikelijke locatie PHP-log? ==
 
[[file:20190913-1347.png|thumb|Locatie php-log achterhalen? [[Phpinfo()]] is waarschijnlijk verreweg de betrouwbaarste manier om dat te doen. Als je in de output zoekt op ''log'', is dit het meest tastbare dat je tegenkomt ⇒ Het is dus het Apache-log]]
 
  
 
Waar je dat log zoal vindt:
 
Waar je dat log zoal vindt:
  
 
  /var/log/apache2/error.log - Onduidelijk: Dit lijkt toch echt een Apache-log te zijn
 
  /var/log/apache2/error.log - Onduidelijk: Dit lijkt toch echt een Apache-log te zijn
 
  
 
== Zie ook ==
 
== Zie ook ==
  
 
* [[PHP-instellingen (hosting)]]
 
* [[PHP-instellingen (hosting)]]

Versie van 13 sep 2019 15:54

Waar worden log-instellingen geconfigureerd?

Het is vaak puzzelen waar PHP-configuraties worden bewaard. Vooral omdat er vaak verschillende sets van configuraties op één en dezelfde computer staan. Ik heb sterk de indruk dat deze instellingen doorgaans in een php.ini-bestand staan. Zie PHP-instellingen (hosting) voor details.

Wat voor log-instellingen zijn er?

Er zijn in ieder geval twee manieren om de loggerelateerde instellingen te achterhalen:

phpinfo

De zekerste manier om loginstellingen te achterhalen, is middels Phpinfo(), omdat je dan zeker weet, dat je de actuele instellingen hebt. Als je in de output zoekt op log, is dit het meest tastbare dat je tegenkomt ⇒ Het is dus het Apache-log

php.ini

Een php.ini-bestand bestaat uit een aantal secties. Dit is een voorbeeld van zo'n sectie op m'n laptop. Deze is weinig geoptimaliseerd (sep. 2019):

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

; This directive informs PHP of which errors, warnings and notices you would like
; it to take action for. The recommended way of setting values for this
; directive is through the use of the error level constants and bitwise
; operators. The error level constants are below here for convenience as well as
; some common settings and their meanings.
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
; those related to E_NOTICE and E_STRICT, which together cover best practices and
; recommended coding standards in PHP. For performance reasons, this is the
; recommend error reporting setting. Your production server shouldn't be wasting
; resources complaining about best practices and coding standards. That's what
; development servers and development settings are for.
; Note: The php.ini-development file has this setting as E_ALL. This
; means it pretty much reports everything which is exactly what you want during
; development and early testing.
;
; Error Level Constants:
; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR           - fatal run-time errors
; E_RECOVERABLE_ERROR  - almost 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 is 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
; E_DEPRECATED      - warn about code that will not work in future versions
;                     of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
;
; Common Values:
;   E_ALL (Show all errors, warnings and notices including coding standards.)
;   E_ALL & ~E_NOTICE  (Show all errors, except for notices)
;   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)
;   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; http://php.net/error-reporting

; Strompf
;;;;;;;;;;;;;;;;;;;;;;;;;
;
error_reporting = E_ALL

; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; For production environments, we recommend logging errors rather than
; sending them to STDOUT.
; Possible Values:
;   Off = Do not display any errors
;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
;   On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
;display_errors = Off

; strompf
;;;;;;;;;;;;;;;;;;;;;;;;;
;
display_errors = On

; The display of errors which occur during PHP's startup sequence are handled
; separately from display_errors. PHP's default behavior is to suppress those
; errors from clients. Turning the display of startup errors on can be useful in
; debugging configuration problems. We strongly recommend you
; set this to 'off' for production servers.
; Default Value: Off
; Development Value: On
; Production Value: Off
; http://php.net/display-startup-errors

; display_startup_errors = Off
display_startup_errors = On

; Besides displaying errors, PHP can also log errors to locations such as a
; server-specific log, STDERR, or a location specified by the error_log
; directive found below. While errors should not be displayed on productions
; servers they should still be monitored and logging is a great way to do that.
; Default Value: Off
; Development Value: On
; Production Value: On
; http://php.net/log-errors
log_errors = On

; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
; http://php.net/log-errors-max-len
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line unless ignore_repeated_source is set true.
; http://php.net/ignore-repeated-errors
ignore_repeated_errors = Off

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; source lines.
; http://php.net/ignore-repeated-source
ignore_repeated_source = Off

; If this parameter is set to Off, then memory leaks will not be shown (on
; stdout or in the log). This has only effect in a debug compile, and if
; error reporting includes E_WARNING in the allowed list
; http://php.net/report-memleaks
report_memleaks = On

; This setting is on by default.
;report_zend_debug = 0

; Store the last error/warning message in $php_errormsg (boolean). Setting this value
; to On can assist in debugging and is appropriate for development servers. It should
; however be disabled on production servers.
; Default Value: Off
; Development Value: On
; Production Value: Off
; http://php.net/track-errors
track_errors = Off

; Turn off normal error reporting and emit XML-RPC error XML
; http://php.net/xmlrpc-errors
;xmlrpc_errors = 0

; An XML-RPC faultCode
;xmlrpc_error_number = 0

; When PHP displays or logs an error, it has the capability of formatting the
; error message as HTML for easier reading. This directive controls whether
; the error message is formatted as HTML or not.
; Note: This directive is hardcoded to Off for the CLI SAPI
; Default Value: On
; Development Value: On
; Production value: On
; http://php.net/html-errors
html_errors = On

; If html_errors is set to On *and* docref_root is not empty, then PHP
; produces clickable error messages that direct to a page describing the error
; or function causing the error in detail.
; You can download a copy of the PHP manual from http://php.net/docs
; and change docref_root to the base URL of your local copy including the
; leading '/'. You must also specify the file extension being used including
; the dot. PHP's default behavior is to leave these settings empty, in which
; case no links to documentation are generated.
; Note: Never use this feature for production boxes.
; http://php.net/docref-root
; Examples
;docref_root = "/phpmanual/"

; http://php.net/docref-ext
;docref_ext = .html

; String to output before an error message. PHP's default behavior is to leave
; this setting blank.
; http://php.net/error-prepend-string
; Example:
;error_prepend_string = "<span style='color: #ff0000'>"

; String to output after an error message. PHP's default behavior is to leave
; this setting blank.
; http://php.net/error-append-string
; Example:
;error_append_string = "</span>"

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog

;windows.show_crt_warning
; Default value: 0
; Development value: 0
; Production value: 0

Gebruikelijke locatie PHP-log?

Waar je dat log zoal vindt:

/var/log/apache2/error.log - Onduidelijk: Dit lijkt toch echt een Apache-log te zijn

Zie ook