Xdebug: Difference between revisions
imported>JasonWoof Show how to install/configure xdebug with apache and vscode |
imported>Onny mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[https://xdebug.org xdebug] is a PHP extension that helps with debugging [[PHP]] code. | |||
== Installation == | |||
== | |||
Configure your local apache/php to have the xdebug extension installed and enabled: | Configure your local apache/php to have the xdebug extension installed and enabled: | ||
Line 20: | Line 16: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Usage == | |||
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". | 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". |
Latest revision as of 17:45, 16 January 2023
xdebug is a PHP extension that helps with debugging PHP code.
Installation
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
'';
};
Usage
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.