PHP Xdebug Visual Code
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
[PHP]
zend_extension="xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
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)
END UPDATE
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
}
]
}
comments powered by Disqus