GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing www.mediawiki.org — Manual:How to debug - MediaWiki (Redirected from XDebug) This page gives a basic introduction to debugging MediaWiki software. One of the first things you will notice is that "echo" generally does not work; this is part of the general design. Security: This should never be enabled on a live public wiki as it could expose private information.
There are several configuration options to aid debugging. The following are all
Example line to be added in your LocalSettings.php : $wgShowExceptionDetails = true; PHP errorsTo see PHP errors, add this to the second line from the top (right below the error_reporting( -1 ); ini_set( 'display_errors', 1 ); Or set it in php.ini : error_reporting = E_ALL display_errors = On Or set in .htaccess: php_value error_reporting -1 php_flag display_errors On This will cause PHP errors to be shown on-page. This might make it easier for attackers to find a way into your server, so disable it again when you have found the problem. Note that fatal PHP errors may happen before the lines above are ever executed, or may prevent them from being shown.
Fatal PHP errors are usually logged to Apache's error log – check the Turning display_startup_errors onSome providers turn --- index.php error_reporting( -1 ); ini_set( 'display_startup_errors', 1 ); ini_set( 'display_errors', 1 ); In other environments: --- myTestFile.php error_reporting( -1 ); ini_set( 'display_startup_errors', 1 ); ini_set( 'display_errors', 1 ); require 'your_file.php'; SQL errorsTo log all SQL queries, rather than just the one that raised the exception, set $wgDebugDumpSql in $wgDebugDumpSql = true; In-depth debuggingDebuggerYou can debug your code step-by-step with XDebug . For some common setups, see:
MediaWiki-Vagrant has built in settings for this. If you're not using MediaWiki-Vagrant, but your setup is similar, you can reuse those values. In some cases (e.g. due to a firewall), you may have to use the IDE on the same machine as the web server. In this case, simply set: xdebug.remote_enable = 1 xdebug.remote_host = 'localhost' See the XDebug documentation for more information. To debug a command-line script (e.g. PHPUnit, or a maintenance script) on MediaWiki-Vagrant, use: xdebug_on; php /vagrant/mediawiki/path/to/script.php --wiki=wiki ; xdebug_off Adjust the script, parameters, and remote host (it should be the IP of the computer where your IP is, 10.0.2.2 should work for MediaWiki-Vagrant) as needed. LoggingFor much greater detail, you need to profile and log errors. The instructions below are only valid for the default configuration. If you change
$wgMWLoggerDefaultSpi , for example to enable the psr3 role on a vagrant box, these settings will probably be ignored. In this case, see the documentation of your logger, for example, Manual:MonologSpi .Setting up a debug log fileTo save errors and debugging information to a log, add The MediaWiki software must have permissions from your operating system to create and write to this file, for example in a default Ubuntu install it runs as user & group /** * The debug log file must never be publicly accessible because it contains private data. * But ensure that the directory is writeable by the PHP script running within your Web server. * The filename is with the database name of the wiki. */ $wgDebugLogFile = "/var/log/mediawiki/debug-{$wgDBname}.log"; This file will contain much debug information from MediaWiki core and extensions. Some subsystems write to custom logs, see #Creating a custom log file to capture their output.
Creating custom log groupsIf you're debugging several different components, it may be useful to direct certain log groups to write to a separate file. See $wgDebugLogGroups for more information. To set up custom log groups, use the following to LocalSettings.php: /** * The debug log file should not be publicly accessible if it is used, as it may contain private data. * However, it must be in a directory to which PHP run within your web server can write. * * Contrary to wgDebugLogFile, it is not necessary to include a wiki-id in these log file names if you have multiple wikis. * These log entries are prefixed with sufficient information to identify the relevant wiki (web server hostname and wiki-id). */ // Groups from MediaWiki core $wgDBerrorLog = '/var/log/mediawiki/dberror.log'; $wgDebugLogGroups = [ 'exception' => '/var/log/mediawiki/exception.log', 'resourceloader' => '/var/log/mediawiki/resourceloader.log', 'ratelimit' => '/var/log/mediawiki/ratelimit.log', // Extra log groups from your extension #'myextension' => '/var/log/mediawiki/myextension.log', #'somegroup' => '/var/log/mediawiki/somegroup.log', ]; To log to one of these groups, call if ( $module->hasFailed ) { wfDebugLog( 'myextension', "Something is not right, module {$module->name} failed." ); } If you have carefully followed the instructions above but nothing gets written to your logging file(s), and if your system is using SELinux, have a look at the logging section on the SELinux page to get around this SELinux context issue.
Writing log files to the
/tmp directory may not generate any log file at all, even if the /tmp directory is supposed to be writable by anyone. This could happen if your system is using one of the systemd features that create a virtual /tmp directory for that process. If that's the case, configure your log file to be written into a different directory, like /var/log/mediawiki
Structured logging
Structured logging allows you to include fields in your log records. See Structured logging for more information. You will need to configure a better logger to collect the extra fields, for example Monolog.
JavaScript error logging
See the documentation of the mediawiki.errorLogger ResourceLoader module. StatisticsAdvanced client-side logging can be performed with Extension:EventLogging , which requires a complex setup and careful inspection of privacy issues. Simple counting of certain kind of events is possible (since MediaWiki 1.25) using StatsD. StatsD offers meters, gauges, counters, and timing metrics. Usage example: $stats = $context->getStats(); $stats->increment( 'resourceloader.cache.hits' ); $stats->timing( 'resourceloader.cache.rtt', $rtt ); The metrics can be sent to a StatsD server, which may be specified via the As of MediaWiki 1.25, Send debug data to an HTML comment in the outputThis may occasionally be useful when supporting a non-technical end-user. It's more secure than exposing the debug log file to the web, since the output only contains private data for the current user. But it's not ideal for development use since data is lost on fatal errors and redirects. Use on production sites is not recommended. Debug comments reveal information in page views which could potentially expose security risks. $wgDebugComments = true; Working live with MediaWiki objectseval.php is an interactive script to evaluate and interact with MediaWiki objects and functions in a fully initialized environment. $ php maintenance/run.php eval
> print wfMessage("Recentchanges")->plain();
Recent changes
The MediaWiki-Vagrant portable virtual machine integrates the interactive PHP shell Callable updatesCode embedded in the Interactive shellYou can use shell.php as a PHP REPL with full access to MediaWiki internals. Client side debugging (JavaScript)Wikipedia offers a rich set of tools for debugging client side JavaScript. In addition to the MediaWiki tools, other techniques are available to assist with diagnosing client interactions. Tools:
See also
| ||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |