PHP Xdebug Visual Code

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

UPDATE: PHP 7.4 Every time I do value use php I then lose my xdebug setup :( here is me taking a moment to stop having that happen

vim /usr/local/etc/php/7.4/php.ini

Then add this


xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host =
xdebug.remote_port = 9000
xdebug.remote_mode = req

And then I am set again! Notice I am using 9000 above my insanity of using 9005 below has passed

I put two files in my home directory, one starts with the above and one does not. Then I put this alias into my ~/.zshrc

alias debug_on="cp ~/Code/php.ini.debugon /usr/local/etc/php/7.4/php.ini"
alias debug_off="cp ~/Code/php.ini.debugoff /usr/local/etc/php/7.4/php.ini"

source ~/.zshrc

and now I can easily turn this on and off to save TONS of time with any php job (testing, etc)


This article got me going on using 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

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


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,

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:
  "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


php xdebug