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.
This is really nice description of the issue, so I'm going to try to help.
This is certainly possible, as I just tried (2017.3.3 here) with two instances of PHPStorm opening two different projects.
I believe issue lies in PHPStorm not knowing which path mapping to use
To tell PhpStorm which path mapping configuration it should use for a connection from a certain machine you need to set the value of the “PHP_IDE_CONFIG” environment variable to “serverName=SomeName”, where ‘SomeName’ is the name of the server configured in ‘Project Settings | PHP | Servers’
If that doesn't help, you should explain more what "it never worked for me" means. You have explained this in scenario 2 only. Xdebug configuration file for these vagrant boxes would also help. Xdebug configuration on local host is not really relevant.
Hi @Gadelat,
How do I setup the same ENV variable on only one box?
I think that maybe you miss this part "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)."
With that being said, still possible to achieve this using your recommended setup? If so I will need more guidance since I don't see how to do it (I don't need you to teach me how to register the ENV var, I just need to see how or what steps did you follow in order to achieve it).
As for the Xdebug configuration, here it's:
xdebug.default_enable = 1
xdebug.idekey="PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 1
xdebug.remote_port = 9001
For the first two scenarios, go to Preferences | Languages & Frameworks | PHP | Debug and
Try again, I expect that requests coming from different projects should no longer intrude a wrong IDE window.
The third one, AFAICS, is similar to the first one except for having both projects open in the same window. This isn't gonna work, as currently this multi-frame UI implementation is in fact one project including all open ones, they even share the code base.
Also, you have wrong mappings there - /var/html instead of /vagrant/html
@Eugene,
I have made the changes as you suggested and the debugging is working properly which means is going to the right IDE window. I have opened the A app and started making calls there and Xdebug is going to the right IDE as I said before but is not jumping between them when calls to the API on B are being made. I would expect something like the following:
Here is how A and B IDE's are setup:
IDE for A app:
Xdebug is enabled on the browser and I am browsing a URL belonging to A app:
There is NO configurations for debugging at all and a break point has been set. The IDE is stopping there and is debugging properly. This is cool!
Here is the PHP > Servers setup (I have fixed the path mapping on the server side)
And finally here is the debugger setup
IDE for B app:
Again no debugging setup has been set for this project but a break point has been set however the app is never stopping at that break point is like it does not exists.
Here is the PHP > Servers setup (wrong path has been fixed as well)
And finally the Debugger setup:
> At some point A is making calls to B, B is opened in another IDE I would expect to be able to debug those calls also at B IDE => this is not working
Does Xdebug start on server B though?
I have a feeling that your API calls do not initiate a debugging session, so no wonder it doesn't work.
To check that you can change xdebug.remote_autostart to 1 on server B and restart the web server.
Does it work now?
If it still does not, we need to take a look at the Xdebug remote log for this server: https://intellij-support.jetbrains.com/hc/en-us/articles/206544819-How-to-collect-remote-log-for-XDebug
@Eugene,
If I am following you correctly then you've missed this part: "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)." in a few words A and B are running on the same server so both are using the same Xdebug setup (posted above).
I have enabled Xdebug logs but is not logging anything ... wrong permissions? Should I give Apache RW permissions on that file? Currently it's owned by "root"
@Eugene,
I have set `xdebug.remote_autostart=1` and then also the Xdebug logs and I have posted here
However the second IDE where project B is setup did never start debugging
Unfortunately, I see no events related to document.api in the log.
For some reason, Xdebug doesn't start there.
Could you please call the B API with the REST client or somehow else and check if a debugging session starts?
Well you're right no events appear on the logs but I am seeing the call being made because it gets stored in the DB in a logs table. This is a cURL call that happen behind scenes, could that be the cause?
If I try the API directly from let's say Postman it works and did start debugging properly
@Vladimir,
Yes I've tried without success that the scenario 3 :(
Apologies, I missed that somehow.
Did I understand correctly that you tried to debug B only without other instance with A? Was it successful?
Are deployment configurations for A and B the same? Are mappings specified correctly there and in Languages & Frameworks | PHP | Servers?
@Vladimir,
I am trying to debug to different projects (is all on the OP). So A and B are different apps, different path, different IDE but A is calling internally B through cURL I would like to keep the debugging when A makes any call to B, is that clear?
I don't have deployment configs for any of them
@reynierpm That's surely clear. I just wanted to clarify all the possible things.
You synchronize the files with Vagrant VM via shared folders, correct?
Did you try to pass Xdebug cookie with the cURL request to B as mentioned, for example, at https://ericdraken.com/php-debugging-with-phpstorm-and-xdebug/ - chapter #6?
Just to prove that it actually works in PhpStorm: https://screencast-o-matic.com/watch/cFnVjno411
https://gist.github.com/eugenemorozov-jb/2262e8d876a6c4a15061f4d5b3c2cbd3
So, there must be something wrong about your interpreter or its setup - we really need to understand why the second session doesn't start.
@Vladimir,
Yes I do synchronize files using shared folders and I didn't tried and I will not able to because that will involve change CORE code and they will not accept such thing :( so that's not an option for me.
@Eugene:
Ok it's working for you but what can I do in order to help you to find out why the second session is never started?
@Vladimir @Eugene,
having two IDE instances open, each of them setup for different projects and even different path in Server configuration each time I start a debugging session from the domain `http://erx.localhost:8080` I would expect to start debugging on the IDE where that project is setup however I am asked to choose which file to debug which is confusing - at least for me - see images below:
Why? Can be because of both IDE are setup to listen on port 9001 and one is taking precedence over the second one?
> Can be because of both IDE are setup to listen on port 9001 and one is taking precedence over the second one?
Definitely no, PhpStorm is able to deal with multiple connections coming to the same port.
> Why?
Please confirm that the "Ignore external connections through unregistered..." and all kinds of "Break at first line" is disabled, and also both instances have Listening for incoming connections enabled.
@Eugene yes everything is disabled and both are listening:
What else do you want me to check?
Sorry, my bad, "Ignore external connections" should actually be enabled.
@Eugene, ok apparently that fixes the previous issue but I am still not able to jumping between IDE's when the cURL request is made behind scenes. I have also put a breakpoint where the curl call is:
But it doesn't break on the other ID .... :(
So the session starts for the first domain only?
remote_autostart is still enabled, correct?
Please check the Xdebug log I shared above, in the middle of the log, there's a new session starting for the second domain.
The same thing should happen for you when remote_autostart is enabled.
If it doesn't happen - there's something wrong with the Xdebug configuration, but I don't know what exactly. I know that we've talked this over already, but is there a chance the other domain uses a different interpreter, or a different php.ini?
Could you please confirm with phpinfo() that it also has remote_autostart enabled?
@Eugene yes both are enabled and both uses the same php.ini. I am seeing this in the xdebug.log file (full file here):
Log opened at 2018-02-05 20:50:47
I: Checking remote connect back address.
I: Remote address found, connecting to 127.0.0.1:9001.
E: Could not connect to client. :-(
Log closed at 2018-02-05 20:50:47
The AV stopping connections? Why if it does work for the first IDE does not for the 2nd?
I don't know, it shouldn't be that way since you have simultaneous connections set to 5.
What if you set remote_connect_back to 0, remote_host to 127.0.0.1 and restart the web server?
@Eugene, if I do that then I got this instead:
Log opened at 2018-02-06 13:10:01
I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(
Log closed at 2018-02-06 13:10:01
Maybe it's Windows Firewall, or a firewall provided by AV software?
@Eugene, well the company I work for uses Symantec Endpoint Protection. See the following pics, looks like the AV is blocking the IP address right?
Well I have reverted my setup and I am able to debug only in one IDE so I would discard Firewall issues ... right?
> Well I have reverted my setup and I am able to debug only in one IDE so I would discard Firewall issues ... right?
I don't know. My idea was that the firewall blocks the connection if there's one already established for this port. I've never seen any firewall configured this way, but right now it seems to be the only explanation.
I suggest that we have a remote session via TeamViewer. Please submit a ticket to our HelpCenter (leave a note so the person that gets it would assign it to me):
https://intellij-support.jetbrains.com/hc/en-us
@Eugene I am not allowed to do a live TeamViewer section at work but I am setting up the exact thing at home where we can work on that. However I am using Docker and I am not able to setup this properly meaning the debugger. (see this question).
Note: The OP refers to two apps on the same VM but in this case I have split them into different containers (I am planning to move into Docker and get rid of Vagrant soon) so maybe this one is a little different from the one above but at the end is the same approach.
Hi there @Eugene, it's being a while since we tried something here but I continue with the same issue which means no matter what I do is always trying to connect to the IP address `127.0.0.1` and I can't find what I am doing wrong. First of all I look for the IP address in the Vagrant which is as follow:
Having the above information here is what I have tried for the last 4 hours just today and sadly without success. For all of the xDebug configuration bellow and each attempt I have tried the following headers on the cURL request as explained here (Step 6):
1st attempt) xDebug setup :
xdebug.log result:
I: Checking remote connect back address.
I: Remote address found, connecting to 127.0.0.1:9001.
E: Could not connect to client. :-(
I: Checking remote connect back address.
I: Remote address found, connecting to 127.0.0.1:9001.
E: Could not connect to client. :-(
[xdebug]
xdebug.idekey="PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 1
xdebug.remote_port = 9001
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_handler = "dbgp"
; Select a connect-back IP from the $_SERVER['...'] value set in a custom header
xdebug.remote_addr_header = "HTTP_X_XDEBUG_REMOTE_ADDRESS"
I: Checking remote connect back address.
I: Remote address found, connecting to 127.0.0.1:9001.
E: Could not connect to client. :-(