Xdebug: Difference between revisions
imported>JasonWoof Show how to install/configure xdebug with apache and vscode |
imported>Onny m Minor cleanup |
||
Line 1: | Line 1: | ||
[https://xdebug.org xdebug] is a PHP extension that helps with debugging [[PHP]] code. | |||
xdebug is a PHP extension that helps with debugging [[PHP]] code. | |||
== Line-by-Line Source Debugging PHP in vscode == | == Line-by-Line Source Debugging PHP in vscode == |
Revision as of 17:39, 16 January 2023
xdebug is a PHP extension that helps with debugging PHP code.
Line-by-Line Source Debugging PHP in vscode
Configure your local apache/php to have the xdebug extension installed and enabled:
# in /etc/nixos/configuration.nix (not inside systemPackages)
services.httpd.phpPackage = pkgs.php.buildEnv {
extensions = ({ enabled, all }: enabled ++ (with all; [
xdebug
]));
extraConfig = ''
xdebug.mode=debug
'';
};
In vscode open the debug panel and click "create a launch.json file" and click "PHP". The defaults work. Just click the green triangle "Listen for Xdebug".
Edit a PHP file and add xdebug_break();
where you'd like the debugger to start.
Point your browser at apache to get that PHP file to run in apache. Once that xdebug_break()
xdebug will connect to vscode to initiate the debugging session. Once that connection is made you can make further breakpoints in vscode in the usual way (clicking to the left of the source code).
See upstream xdebug documentation if you'd like other modes e.g. for PHP to connect to vscode and break/pause without the call to xdebug_break()
. The extraConfig string in the above example goes into php.ini.