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?
Please sign in to leave a comment.
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?
No :( if I set that option to 0 it does not connect back to the IDE. The xDebug setup looks like:
See logs below:
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.
Confirmed, is off
Here is some extra info regarding how the box is configured using Vagrant not sure if this could help:
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.
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:
@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:
Thanks a lot for your patience and time!!
Wonderful! Thank you for the update, I am happy we've finally sorted this out.