How to setup phpStorm for debug two projects at the same time?

I have been trying to setup this for a while and I have read a lot about it but sadly I am not able to get this to work. Also I am seeing different scenarios which I will describe below. I don't know if this is possible at PHP/xDebug or if it's not supported by phpStorm so don't call me crazy :p 

There will be always two projects involved A which is the main application and B which is an API. Think on it as an small micro-services architecture with the difference that both are running on the same server which means same PHP, same Apache, same Server (box).

Having said that here are the scenarios:

Scenario 1:

  • Two different instances of phpStorm opened: one have the project A setup, the other one has the project B setup
  • Remote PHP (5.3.3) and Xdebug has been setup in both projects independently however the Xdebug setup from the PHP side (php.ini) is shared between them.
  • The IDE key has been set to: PHPSTORM
  • The Xdebug extension has been installed and enabled in the browser (Chrome)
  • I've open a page from app A and this page makes a request to an endpoint on the app B.
  • I would expect to be able to switch between the IDEs back and forth when this happen so I can keep a track of what the application is doing.
  • Result: it never worked for me

Scenario 2:

  • One instance of phpStorm opened with project B
  • Remote PHP (5.3.3) and Xdebug has been setup.
  • The IDE key has been set to: PHPSTORM
  • The Xdebug extension has been installed and enabled in the browser (Chrome)
  • I've open a page from app A and this page makes a request to an endpoint on the app B.
  • Because the project I have open is B I would expect to be able to debug the API endpoints.
  • Result: is not working because as soon as the IDE knows there is a request doesn't matter where is coming from it tries to debug the wrong project meaning A.

 Scenario 3:

  • One instance of phpStorm opened with two projects: project A and project B
  • Remote PHP (5.3.3) and Xdebug has been setup.
  • The IDE key has been set to: PHPSTORM
  • The Xdebug extension has been installed and enabled in the browser (Chrome)
  • I've open a page from app A and this page makes a request to an endpoint on the app B.
  • I would expect to be able to switch between the projects back and forth while debugging.
  • Result: it never worked for me

Screenshot:

Scenario 2:

Scenario 3:

Why? How should I setup the IDE?

39 comments
Comment actions Permalink

Hi! It seems that due to the thread size we've lost an important detail here - xdebug.remote_connect_back is set to 1.
When the initial connection comes from the host to the VM, it uses the host address to sent debug data back.
But when the app connects to API, it's a localhost connection! So it sends data to localhost.
Please remove remote_connect_back completely and restart Apache. Would that help?

0
Comment actions Permalink

No :( if I set that option to 0 it does not connect back to the IDE. The xDebug setup looks like:

[xdebug] 
xdebug.idekey="PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 0
xdebug.remote_port = 9001
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_handler = "dbgp"
;xdebug.remote_host=192.168.50.4

xdebug.remote_addr_header = "HTTP_X_XDEBUG_REMOTE_ADDRESS"

See logs below:

Log opened at 2018-05-29 18:54:22 
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-05-29 18:54:22

Log opened at 2018-05-29 18:54:23
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-05-29 18:54:23

Log opened at 2018-05-29 18:54:23
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-05-29 18:54:23

Log opened at 2018-05-29 18:54:56
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-05-29 18:54:56

Log opened at 2018-05-29 18:54:56
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-05-29 18:54:56
0
Comment actions Permalink

Could you please confirm with phpinfo() that the parameter has been set to 0?
It can be a wrong .ini file (e.g. the CLI one) or you did not restart Apache so that the changes weren't applied.
Otherwise, it looks like pure magic.

0
Comment actions Permalink

Confirmed, is off

0
Comment actions Permalink

Here is some extra info regarding how the box is configured using Vagrant not sure if this could help:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "CentOS-6.5-x86_64"
config.vm.box_url = "centos65-x86_64-20131205.box"

config.vm.provision :shell, :path => "bootstrap.sh"

config.vm.network "private_network", ip: "192.168.50.4"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network "forwarded_port", host: 33060, guest: 3306

config.vm.synced_folder "../../www", "/vagrant", :owner=>"apache", :group=>"apache"
config.vm.synced_folder "../../media/", "/media" , :owner=>"root", :group=>"root"

config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
0
Comment actions Permalink

Oh, I didn't notice that the xdebug.remote_host parameter is commented out. Why?
And the value of the parameter is also questionable
For me, in my Vagrant setup, this parameter is set to the host IP address. If you're using NAT in Vagrant (it seems that you are), you should do the same.

Update: Just saw your message. So, what IP address can the VM use to connect to the host? You should use that one.

0
Comment actions Permalink

It was commented because I was trying different configurations for xDebug. I have followed your suggestions and now it seems to be working (see logs below) however it does not step into the breakpoints for API app not sure what else I am missing here:

Log opened at 2018-05-29 19:34:11
I: Connecting to configured address/port: 192.168.56.1:9001.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///vagrant/html/api/public/index.php" language="PHP" protocol_version="1.0" appid="11604" idekey="PHPSTORM"><engine version="2.2.7"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2015 by Derick Rethans]]></copyright></init>

<- feature_set -i 1 -n show_hidden -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>

<- feature_set -i 2 -n max_depth -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>

<- feature_set -i 3 -n max_children -v 100
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>

<- feature_set -i 4 -n extended_properties -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" status="starting" reason="ok"><error code="3"><message><![CDATA[invalid or missing options]]></message></error></response>

<- feature_set -i 5 -n notify_ok -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" status="starting" reason="ok"><error code="3"><message><![CDATA[invalid or missing options]]></message></error></response>

<- stdout -i 6 -c 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stdout" transaction_id="6" success="1"></response>

<- status -i 7
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="status" transaction_id="7" status="starting" reason="ok"></response>

<- step_into -i 8
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="8" status="break" reason="ok"><xdebug:message filename="file:///vagrant/html/api/public/index.php" lineno="21"></xdebug:message></response>

<- eval -i 9 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="9"><property address="140735422311104" type="bool"><![CDATA[0]]></property></response>

<- eval -i 10 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="10"><property address="140735422311104" type="bool"><![CDATA[1]]></property></response>

<- eval -i 11 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="11"><property address="140735422311104" type="string" size="7" encoding="base64"><![CDATA[YXBpLmRldg==]]></property></response>

<- eval -i 12 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="12"><property address="140735422311104" type="string" size="2" encoding="base64"><![CDATA[ODA=]]></property></response>

<- eval -i 13 -- KHN0cmluZykoJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="13"><property address="140735422311104" type="string" size="25" encoding="base64"><![CDATA[L3YxL2RvY3VtZW50cy9nZXRfYnlfaWQvMQ==]]></property></response>

<- run -i 14
-> <stream xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" type="stdout" encoding="base64"><![CDATA[eyJyZXF1ZXN0Ijp7InN1Y2Nlc3MiOnRydWUsInVpZCI6IjViMGRhYjMzZGE3NTUiLCJjb2RlIjoyMDAsImNhY2hlYWJsZSI6ZmFsc2UsImVycm9ycyI6W10sIm1lc3NhZ2UiOiIifSwicmVzcG9uc2UiOlt7ImRvY3VtZW50X2lkIjoiMSIsImV4dGVybmFsX2lkIjoiYWM0YzIiLCJ1c2VyX2lkIjoiMSIsImRhdGVfY3JlYXRlZCI6IjIwMTgtMDUtMjkgMTk6MzI6NDkiLCJsb2NhdGlvbl9pZCI6IjMyIiwicmVmZXJyYWxfaWQiOm51bGwsImNhc2VfaWQiOm51bGwsInB0X2lkIjoiODYiLCJ3b3JrZmxvd19uYW1lIjoiamFuc3NlbiIsInJ4X2lkIjoiMSIsImRvY3VtZW50X25hbWUiOiJqYW5zc2VuX3BhdGllbnRfYXV0aF9hYzRjMi5wZGYiLCJkb2N1bWVudF9vcmlnIjpudWxsLCJkb2N1bWVudF90eXBlIjoiUGF0aWVudCBBdXRob3JpemF0aW9uIiwiZG9jdW1lbnRfc2l6ZSI6IjM3MTY0MSIsImRvY3VtZW50X2NvbnRhaW5lciI6ImVjYXNlamFuc3NlbmRldiIsImRvY3VtZW50X2ZvbGRlciI6ImRhdGFcL3BkZlwvIiwibHVuX2lkIjpudWxsLCJkb2N1bWVudHNlcnZpY2VfaWQiOiJhMjJiN2E2Zi05OGNiLTQwNjgtYWM2MC0yNWRkNGY4ODFlNTIifV19]]></stream>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="14" status="stopping" reason="ok"></response>

<- stop -i 15
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="15" status="stopped" reason="ok"></response>

Log closed at 2018-05-29 19:34:12

-> <stream xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" type="stdout" encoding="base64"><![CDATA[eyJkb2N1bWVudF9pZCI6IjEiLCJleHRlcm5hbF9pZCI6ImFjNGMyIiwidXNlcl9pZCI6IjEiLCJkYXRlX2NyZWF0ZWQiOiIyMDE4LTA1LTI5IDE5OjMyOjQ5IiwibG9jYXRpb25faWQiOiIzMiIsInJlZmVycmFsX2lkIjpudWxsLCJjYXNlX2lkIjpudWxsLCJwdF9pZCI6Ijg2Iiwid29ya2Zsb3dfbmFtZSI6ImphbnNzZW4iLCJyeF9pZCI6IjEiLCJkb2N1bWVudF9uYW1lIjoiamFuc3Nlbl9wYXRpZW50X2F1dGhfYWM0YzIucGRmIiwiZG9jdW1lbnRfb3JpZyI6bnVsbCwiZG9jdW1lbnRfdHlwZSI6IlBhdGllbnQgQXV0aG9yaXphdGlvbiIsImRvY3VtZW50X3NpemUiOiIzNzE2NDEiLCJkb2N1bWVudF9jb250YWluZXIiOiJlY2FzZWphbnNzZW5kZXYiLCJkb2N1bWVudF9mb2xkZXIiOiJkYXRhXC9wZGZcLyIsImx1bl9pZCI6bnVsbCwiZG9jdW1lbnRzZXJ2aWNlX2lkIjoiYTIyYjdhNmYtOThjYi00MDY4LWFjNjAtMjVkZDRmODgxZTUyIn0=]]></stream>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="46" status="stopping" reason="ok"></response>

<- run -i 47
Log closed at 2018-05-29 19:34:12
0
Comment actions Permalink

@Eugene, I have found the latest issue which is for some reason the domain internally is changed to dev and the port to 80 so api.localhost:8080 from inside the box is api.dev. In other words:

  • From outside the API can be accessed like: api.localhost:8080 (this is how I had setup the Server configuration)
  • From inside the API can be accessed like: api.dev (since a cURL call happen inside the box, changing the server configuration makes it to work)

Thanks a lot for your patience and time!!

0
Comment actions Permalink

Wonderful! Thank you for the update, I am happy we've finally sorted this out.

0

Please sign in to leave a comment.