Search code examples
phpphpstormxdebug

Using PhpStorm for Remote Debugging - something not quite right


I am following steps here to perform debugging on remote server:

https://www.jetbrains.com/help/phpstorm/remote-debugging-via-ssh-tunnel.html

Locally I am using MAC Sierra.

In PhpStorm I have PHP 7.0 as CLI, and it shows Xdebug is installed. In the php.ini I have

zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

phpinfo also shows Xdebug is enabled.

Under Preferences->Languages->PHP->debug I have port 9000 set for Xdebug and Enable remote connections is checked. I also set Break at first line just to be sure.

I also have SSH tunnel up and running via this command from my MAC terminal:

ssh -R 9000:localhost:9000 [email protected]

which successfully established SSH connection.

I restarted Apache on my local computer, set breakpoint at index.php file of the remote site (though this amounts to setting breakpoint in local file, but my understanding that is how this works and I have path mapping set up), enabled listen to incoming debug connections, installed xdebug extension for chrome and enabled it, loaded the remote page in question, but PhpStorm does not break.

Now, based on the instructions, I didn't see that I have to do any setup on the remote server. My understanding is that if I type an address in the browser after doing required steps it will trigger break in PhpStorm.

I feel like I am missing something.

Ideas?


Solution

  • If you use ssh -R 9000:localhost:9000 [email protected], that indicates that the server/PHP you want to debug is at myremotesite.com.

    With that, the following statement is incorrect:

    Now, based on the instructions, I didn't see that I have to do any setup on the remote server.

    You're debugging PHP on the remote server, and that is of course where you need to do the set-up. Xdebug lives inside PHP, and hence needs to be available on the remote Web server.

    The settings that you need to make on the remote server should be so that it connects to your exposed SSH tunnel port. That means that the host/port that Xdebug needs to connect to is localhost:9000, and no longer remote_ip. Hence, these settings should work:

    xdebug.remote_enable=1
    xdebug.remote_port=9000
    xdebug.remote_host=localhost
    

    As the last two settings are already the default, you could even leave them out, and just use xdebug.remote_enable=1.

    In case you want to see what Xdebug does, also set xdebug.remote_log=/tmp/xdebug.log. This will log connection attempts (if they exist) and also the full communication.

    I restarted Apache on my local computer

    That would also not be needed, as your local Apache is not involved in debugging remote requests (i.e., the ones that run on myremotesite.com's Apache.