PhpStorm, Apache + PHP + xDebug on same machine, browser remote

Hello,

I have trouble to get debugging to work with the following setup:

VM with latest Linux Mint x64, Apache 2.4, PHP 5.5, xDebug 2.2.5 and PhpStorm 9.0.2. Debugging from browsers inside the VM is no problem. But how can I debug requests coming from outside the VM like from the Host (IE, Visual Studio/App development) or any tablet via wifi? Which is the correct setup for PhpStorm + xDebug to get this working? Port 9000 is open on any devices and there is traffic between the device doing the request and the VM in both directions.

0
4 comments

Hi there,

As I understand you have 3+ devices (real or virtual): VM where code runs, Your computer where IDE is running .. and then some another device where you browse the pages/sending requests. And you want to debug such requests (that were made on another device) on your computer? Did I get your setup correctly?

1) To initiate debug session you have to:
a) either pass xdebug cookie or GET/POST parameter together with the actual request (e.g. Firefox addon, Chrome one)
b) have something like xdebug_break(); in your code (programmatic breakpoint)
c) configure your xdebug to attempt to debug every single request automatically (xdebug.remote_autostart = 1)

2) If IDE runs on your computer (and not inside VM where site is running) then you will also have to provide path mappings so that IDE can map local paths to remote ones.

3) Make sure that xdebug tries to connect to your IP and not some another.

https://confluence.jetbrains.com/display/PhpStorm/Debugging+with+PhpStorm

0

Hi Andriy,

yes, I have 3+ devices. But no, IDE is not running on my computer. It is running inside VM where code is running.

I had that first, code in VM, IDE on host computer, accessing files remote via samba share. But even via a virtual network and with 16GB RAM on host that is kind of slow. Then I tried the variant synching code betwenn local and remote. Uploading file changes is very smooth but downloading changes after a git pull, git checkout to other branch or drush up / drush dl gives time for a double coffee break. And furthermore I could not get debugging local PHP scripts on the remote located outside the samba share to work, e. g. Drush itself.

That's the reason why I want to have IDE inside the VM, second reason is that I can export and share the whole development environment as part of the VM with other developers of my team, so that everybody uses the exact same setup. The only additional task for that is removing my personal settings like SSH key, git user.* config and my PhpStorm license before exporting.

About the steps you listed:

1. a & c, 2.: ok
1. b: didn't know about this. Will try it.
3. Which IP address, of the VM or the machine triggering the request?

0

Since IDE is on the same host as actual code (both inside VM) then you do not need to forward xdebug port anywhere -- it's all local.

IP -- just make sure it's 127.0.0.1 (or localhost) -- this should be enough. In general -- it should be an IP where debug client (PhpStorm in our case) is located.

The "main" thing here is to initiate actual debug session, which should be done on requestor side (unless you do b) or c) ).

P.S.
Another possible idea .. is if you have nginx (or any other tool) acting like reverse proxy in front of your Apache .. then you could automatically add such xdebug cookie/GET param to any/specific requests (by using some equivalent of mod_rewrite in Apache: tool checks all incoming requests, sees the ones you want to debug (e.g.. coming from specific IP/browser ID etc) and adds such debug info into request when forwarding it further for Apache for processing). This is just an idea (based on what such tool a capable of) -- I have not done anything like that myself.

0

Thanks, I checked it again and now it works. I copied over the xdebug settings from php.ini from my old VM and there I needed to enable xdebug.remote_connect_back. After reading the help about configuration params at http://xdebug.org/docs/all_settings I found that this setting was causing xDebug connecting to my host/tablet which made the HTTP request instead of to the VM where PhpStorm was listening to xDebug.

Another helpful article I found was https://www.deeson.co.uk/labs/debugging-drupal-drush-real-time-phpstorm-and-xdebug about how to setup xDebug and PhpStorm for debugging Drush.

0

Please sign in to leave a comment.