0

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?

2
  • Not a solution, just my workaround - use docker and debug locally :) Commented Oct 8, 2019 at 15:15
  • "My understanding is that if I type an address in the browser after doing required steps it will trigger break in PHPStorm." You also need to tell Xdebug to actually start debugging the requested page: you can use GET/POST parameter (manually add it to URL) or use Xdebug helper browser extension for your browser which will setup the same Xdebug COOKIE for you. Xdebug will not try to debug a script unless: 1) it sees "debug me" flag; 2) configured to debug every single request or 3) yuo have placed programmatic breakpoint (call special Xdebug function in your PHP code) to start debugging. Commented Oct 8, 2019 at 15:49

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for the insight! does that mean in PHPStorm I have to set the PHP CLI to be the remote PHP version that I see when running phpinfo on remote machine?
Ok, working now! This is incredibly useful, thanks again
@Brian 1) You do not need PHP Interpreter in PhpStorm if you plan to debug web page only ... as PHP Interpreter will be used for CLI debugging, not web 2) Apache may use completely different php.ini to what CLI uses (a common case on Mac and Linux). So if you need to check if Xdebug is enabled, do it in the same environment as where you plan to debug (e.g. via web page).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.