Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

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:


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


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.)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

; 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
;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

; 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
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.
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.
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.
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
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
track_errors = Off

; Turn off normal error reporting and emit XML-RPC error XML
;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
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
; 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.
; Examples
;docref_root = "/phpmanual/"

;docref_ext = .html

; String to output before an error message. PHP's default behavior is to leave
; this setting blank.
; 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.
; Example:
;error_append_string = "</span>"

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

; Default value: 0
; Development value: 0
; Production value: 0

Locatie PHP-error-logs?

De crux zit in het volgende stukje uit het php.ini-bestand:

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

Wat hierover zegt:

error_log string

   Name of the file where script errors should be logged. The file should be writable 
   by the web server's user. 

   If the special value syslog is used, the errors are sent to the system logger 
   instead. On Unix, this means syslog(3) and on Windows it means the event log. See 
   also: syslog(). 

   If this directive is not set, errors are sent to the SAPI error logger. For 
   example, it is an error log in Apache or stderr in CLI. See also error_log().


  • Als alles is uit-gecommentariseerd (zoals hierboven), dan moet je bij het Apache-log (of stderr voor cli) zijn
  • Als de regel error_log = php_errors.log actief is, heb je waarschijnlijk een eigen log-bestand met de naam php_errors.log
  • Als de regel error_log = syslog actief is, wordt er gebruik gemaakt van syslog.

De locatie van Apache-logs is gespecificeerd in de virtuele host-definities. Meestal gebruik ik daar deze directives voor:

LogLevel warn
ErrorLog /var/log/apache2/error.log                    # Eén error-log-bestand voor alle domeinen
CustomLog /var/log/apache2/access.log vhost_combined   # Eén access-log-bestand voor alle domeinen, type 'vhost_combined'

Alle virtuele hosts maken dus gebruik van hetzelfde logbestand. Voor mij dus


Zie ook