I have a vagrant box running locally on my mac along with PHP 7.4 and xdebug. I can see xdebug loaded with:
vagrant@vagrant:~$ php -v
PHP 7.4.28 (cli) (built: Feb 17 2022 16:06:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
...and /etc/php/7.4/mods-available/xdebug.ini has:
zend_extension = /usr/lib/php/20190902/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000 #if you want to change the port you can change
My Sublime Text 3/Packages/User/Xdebug.sublime-settings has:
...
"host": "127.0.0.1",
// Which port number Sublime Text should listen
// to connect with debugger engine.
"port": 9000,
...
I tried forwarding port 9000 from vagrant to host and I get an error saying the port is already in use. I'm guessing that is because sublime is using it on the host side.
I had a couple of issues going on. First, I needed the xdebug config methods for xdebug v.3 (not 2). Also, the client_host
needed to be set to the VM's gateway which is 10.0.2.2
rather than 127.0.0.1. You can view your VM's gateway with route -nee
Here are the settings I have in /etc/php/7.4/mods-available/xdebug.ini
zend_extension = /usr/lib/php/20190902/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host= 10.0.2.2
xdebug.client_port = 9000
xdebug.log = /var/log/xdebug.log