PHP Xdebug Visual Code

Posted: 2019-03-28 17:38:43

This article got me going on using Xdebug https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug

But since 7.2 it has been tricky on the Mac.

pecl install xdebug

Then vim /usr/local/etc/php/7.2/php.ini

And remove from there any reference to xdebug.so

Then /usr/local/etc/php/7.2/conf.d/ext-xdebug.ini

[xdebug]
zend_extension="xdebug.so"
xdebug.remote_autostart=1
xdebug.remote_port=9005
xdebug.remote_enable=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/Users/alfrednutile/xdebugtmp/"

and restart the services

brew services restart php72 

You should be able to run php --ini at the command line.

>php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File:         /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.2/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.2/conf.d/ext-xdebug.ini,
/usr/local/etc/php/7.2/conf.d/php-memory-limits.ini

Visual Code's xdebug launch.json looks like:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [{
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9005
    },
    {
      "name": "Launch currently open script",
      "type": "php",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}",
      "port": 9005
    }
  ]
}

Tags:

php xdebug