Manual:How to debug

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.

PHP errors
To see PHP errors, add this to the very top of LocalSettings.php:

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 disabled 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 &mdash; check the error_log setting in php.ini (or use phpinfo).

You can enable more details (like a stack trace) to be shown for some types of errors:

this is especially useful when debugging errors in the PHP code (as opposed to configration problems).

SQL errors
To display SQL errors in error messages instead of "(SQL query hidden)", add the following to LocalSettings.php:

Logging
For much greater detail, you need to profile and log errors.

To save SQL errors to a log, add $wgDebugLogFile to the LocalSettings.php file. Change the value to a text file where you want to save the debug trace output.

Profiling
To add much more detail, you need to enable profiling.

Setting $wgProfiling will give you basic page timing in the file defined by $wgDebugLogFile.

Here there's specific settings that were removed in 1.8, for other settings see below.

To enable profiling, you need to modify the StartProfiler.php file. To enable profiling, you can replace its content by this to use the full profiler.

Then you can customize more thigs in LocalSettings.php (see below).

Common configuration: (both <1.7 and >1.8)

Tracing execution
Once the above is done, you can call the global function wfDebug from wherever in the code you like. The function is defined in the includes/GlobalFunctions.php</tt> file. For example:

When the code was run, this would be added to the log file: This is just testing the debug tracing stuff

Advanced profiling
You can modify StartProfiler.php to load a more advanced profiler. Then, wrap any function that you want to investigate as a bottleneck in the following code:

At the beginning:

At the end:

In the log file you will see profiling info. Change $wgProfileCallTree</tt>in LocalSettings.php</tt> to true or false for different display formats.

Logging to Database
To log profiling to a database, first you'll have to create a profiling table in your MediaWiki database using the command in the file maintenance/archives/patch-profiling.sql , and set $wgProfileToDatabase = true;</tt> in LocalSettings.php.

Note: $wgProfileCallTree</tt> must be set to false.

Now go visit some pages (or let your users do so).

Viewing Profile Info
The page profileinfo.php in the MediaWiki root prints profile info from the profiling table. To run it, set $wgEnableProfileInfo = true;</tt> in AdminSettings.php. Then, after gathering enough data, visit profileinfo.php to see how much time your profiled code is using and how many times it's being called.