Sometimes WP_DEBUG and debug.log isn't enough to track down a problem. Then I need to debug on a local installation and use Xdebug to examine variables in the code.
My technical articles are a mix of posts with code that may be helpful to others and posts that are primarily reference notes for me. I regularly consult the Debugging with WordPress and being secure, Standalone WordPress scripts and Debugging WordPress Email Issues articles to copy the settings or code that I need.
This article, about using Notepad++ as a debug environment, will be one that I will revisit.
I do all my work on big heavy laptop (19″ screen) running Windows 7. While I mostly debug on remote servers where WP_DEBUG is enabled, and this is sufficient, sometimes a problem cannot be solved by this. In such a case, a local setup and proper source level debugging is required.
Download the Xdebug dll. I am using XAMPP for my local development environment. It is running 7.1 I downloaded the PHP 7.1 VC14 TS (32 bit) version (php_xdebug-2.6.0-7.1-vc14.dll) and copied it to c:\xampp\php\ext\php_xdebug-2.6.0-7.1-vc14.dll.
Then I edited c:\xampp\php\php.ini and add the following:
and a xdebug section:
xdebug.profiler_output_dir = "c:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%p"
xdebug.profiler_enable = 0
Restart Apache for the changes to take effect.
Run a page with phpinfo() and you will see the xdebug section with the version (2.6.0) and the IDE Key (this will be needed in the Notepad++ configuration).
You must run the 32 bit version of Notepad++ as the bridge plugin is only available in 32 bit.
Download the DBGP Plugin for Notepad++: DBGpPlugin_0_13b_dll.zip. Copy dbgpPlugin.dll to C:\Program Files (x86)\Notepad++\plugins.
Launch Notepad++ and go to the Plugins/DBGp/Config and enter the details of the Apache server and the path to the document root.
The IDE KEY is the string that will be appended to the url to start the debug session.
Open Notepad++, go to Plugins/DGBp/Debugger to enable the debugger.
Go to the browser and append ‘?XDEBUG_SESSION_START=xdebug‘ to the url to be examined.
Notepad++ will show the first line of code for the appropriate PHP script.
Start debugging. You can add breakpoints and examine local and global variables.