1

I'm following the instructions here to setup xdebug on my local machine on vim. Everything went smooth, until I reached this part:

To initialize a debugging session, XDebug will attempt to make a connection to the remote host and port that you specified above (localhost:9000), so you need to make sure that your Vim is reachable at that address. Unless you're running Vim on the same server as PHP, this may involve building an SSH tunnel back to your development box.

When I run my server locally, I do this:

php artisan serve --host 0.0.0.0 --port 8000

and as instructed, pressing F5 will make vim listen to port 9000:

waiting for a new connection on port 9000 for 10 seconds...

So basically, I want all connections to port 9000 to actually reach my php server at port 8000..

using ssh tunnel, I run this command (which is -L local-port:host:remote-port)

ssh -L 9000:localhost:8000 

but then i get this obnoxious error:

$ ssh -L 9000:localhost:8000
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

what am I doing wrong?

Update

So based on this answer.. I simply did the following:

my xdebug config (located in: /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini, which I got by running php --ini)

zend_extension="/usr/local/Cellar/php71-xdebug/2.5.5/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=8000

I run my php server as mentioned before (no ssh tunnel) I create a breakpoint in my vi by typing :Bp on my vi, I type F5 then I ge this message:

waiting for a new connection on port 9000 for 10 seconds...

then I immediately go to my postman and run a commmand that hits this endpoint:

http://localhost:8000/api/users/login?XDEBUG_SESSION_START=1

but then nothing happens (actually postman hangs), then i get this message from vim:

Connection Timeout

what am I missing?

1

I think you're misreading the instructions. You don't need to connections on port 9000 to be re-directed to port 8000. You just need your PHP server to be able to contact your Vim instance.

To initialize a debugging session, XDebug will attempt to make a connection to the remote host and port that you specified above (localhost:9000), so you need to make sure that your Vim is reachable at that address. Unless you're running Vim on the same server as PHP, this may involve building an SSH tunnel back to your development box.

You are running Vim on the same server as PHP, so you don't need an SSH tunnel. It should just work when you perform the next step of the tutorial.

Sidenote: The error message is simply SSH's usage, which is always printed if you enter a malformed ssh command. In this case, I agree that it's not particularly helpful: try this page or this page for a better explanation of what SSH tunnels are and how to set them up. (Which, again, you don't actually need to do in this instance.)

  • question updated to reflect your answer – abbood Nov 10 '17 at 13:25
  • check out the answer @Rich.. it works well now! – abbood Nov 10 '17 at 13:58
0

Basically the thing that confused me about this was the different actors/settings files. Let's be clear about who they are and what they're doing:

PHP

It's both server AND client:
http server: it listens for http clients on port 8000
xdebug client: connects to the xdebug server on port 9000

vim

xdebug server:, it serves the php client, using the Xdebug protocol (ie the same way http is a protocol).

php had it's own settings file (present in either php.ini or /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini, and it had the following:

..
xdebug.remote_port=8000

the thing that got me confused was that although this file specified the port as 8000, when i ran the debugger on vim, the status message was:

waiting for a new connection on port 9000 for 10 seconds...

which made me go all 🤔, then I realized (with some help) that the vim settings has port 9000 by default, and that port was different than the xdebug port..

my problem is that the xdebug port was set to 8000, whereas the vim one was set to 9000 (again by default).

so fixing the problem was simply changing the above in the xdebug config to

xdebug.remote_port=9000

and that's it!

bonus

an alias to debug stuff with php unit

function debugMethod() {
    php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 ./vendor/bin/phpunit --filter $1 $2 /path/to/tests/$3/$2.php
}
  • 1
    The instructions you linked to state that you should set the xdebug port to 9000 in your PHP config: if you had done that then it should have worked fine in the first place. Instead, your PHP config has the port set to 8000 and you've altered xdebug to listen on that port (instead of the default 9000). Which would be fine, except you've also got your PHP server listening on the same port, which I imagine could cause issues. Either you should use 9000 for xdebug as suggested by the blog post, or you should change the command you use to invoke your PHP server to use a different port. – Rich Nov 10 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.