3

I'm trying to setup Xdebug to help our development cycle but I'm having some difficulty getting it working. I've also never used Xdebug before so maybe I'm misunderstanding how it works.

We're using PHP7 running on Docker containers with nginx in front of it. These Docker containers are hosted on a private VPC on EC2 servers.

I've installed xdebug-2.5.4 through my dockerfile

RUN wget http://xdebug.org/files/xdebug-2.5.4.tgz && tar -xvzf xdebug-
2.5.4.tgz
WORKDIR xdebug-2.5.4
RUN phpize
RUN ./configure
RUN make && cp modules/xdebug.so /usr/lib64/php/modules

I've confirmed that it's installed by checking my installed php modules (php -m)

I've modified my PHP.ini:

[xdebug]
zend_extension = /usr/lib64/php/modules/xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_host="<ip address of machine running docker>"
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_log="/tmp/xdebug.log"

I've modified my PhpStorm preferences with the host as the same IP address and port in xdebug.remote_host and xdebug.remote_port.

However, I'm at a loss as to where to continue from here. It's worth noting that this isn't running a PHP Web Server, but more of a RESTFUL API that we test using Postman. Is it even possible to use xdebug with such a workflow?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Seline
  • 31
  • 2
  • 1) *"I've modified my PHPStorm preferences with the host as the same ip address and port in xdebug.remote_host and xdebug.remote_port"* Please clarify this part .. especially PhpStorm side... because you so not have to configure any IP here in PhpStorm .. only in xdebug settings. 2) "xdebug.remote_enable=on" and "xdebug.remote_enable=1" -- no need to repeat it twice. – LazyOne Sep 24 '17 at 22:14
  • I added the host and port for the DBGp Proxy setting in PHPStorm. And yes, you're right I didn't see the repetition there! I'll remove that – Seline Sep 24 '17 at 22:19
  • 3) *"It's worth noting that this isn't running a PHP Web Server, but more of a RESTFUL API that we test using Postman."* But you are executing PHP code to serve those API requests, right? from debugging POV it does not matter what your code returns -- proper/full HTML page or JSON data. – LazyOne Sep 24 '17 at 22:19
  • Correct, it's still just PHP code. I meant moreso the workflow of using PHPStorm to write code (with automatic deployment) and Postman to test the actual API. – Seline Sep 24 '17 at 22:22
  • Are you actually using DBGp Proxy? It's a separate software which you have to install separately .. and simply not needed for local Docker development (mainly used for remote debug when more than one dev is working with the same server and it must be secure connection (you are behind NAT or just need xdebug connection private) -- over SSH tunnel only). I bet you do not ... so please do not configure what you are not using. – LazyOne Sep 24 '17 at 22:22
  • So .. what is the IP you have configured there? (we are talking about xdebug in php.ini only) It must be an IP of the PC where IDE is running as it's xdebug that connects to client (PhpStorm in our case). – LazyOne Sep 24 '17 at 22:23
  • Have a look at: 1) https://stackoverflow.com/q/46263043/783119 2) https://stackoverflow.com/q/44032296/783119 3) https://stackoverflow.com/q/22944631/783119 . They are more about "local" debug (Docker is run on local PC) but can give you ideas. Please also ensure that xdebug request is able to reach your PC (e.g. firewalls/routers if it's a "direct" connection .. or use some SSH tunnel to connect to your VPC (in such case xdebug must be connecting to "local" address inside the cloud and SSH tunnel will forward that request to your PC)) – LazyOne Sep 24 '17 at 22:27
  • Ohh if it's a separate software, then no I do not have DBGp Proxy. Sorry, I'm new to this side of debugging so I wasn't aware. However, this is remote debug (the docker container is hosted on an EC2 instance and PHPStorm is running on my local laptop). – Seline Sep 24 '17 at 22:28
  • Ahh the IP I have configured is the IP of the EC2 instance running the docker container. Let me try setting it to the IP of my laptop – Seline Sep 24 '17 at 22:30
  • I have updated my last comment -- take that into an account. For direct connection you may need to alter your Amazon firewall (sorry, never used it myself so do not remember how it's called -- only read from others who were doing such remote debug). – LazyOne Sep 24 '17 at 22:32
  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/206345989-Debugging-PHPStorm-on-Windows-with-Amazon-Web-Services – LazyOne Sep 24 '17 at 22:35
  • Thank you! I appreciate the help. Yes, I've already opened up the EC2 security groups to allow these ports access. I'm installing DBGp Proxy now to see if that helps and I'm reading through those links! – Seline Sep 24 '17 at 22:35
  • https://stackoverflow.com/q/45425587/783119 – LazyOne Sep 24 '17 at 22:37
  • 1
    Just in case (if it's got lost in this many-comments content) -- 1) it's xdebug that connects to IDE and not other way around. So xdebug must be able to reach your computer (firewall on AWS must allow outgoing connection on TCP 9000 port; and your local firewall/router must allow incoming connection) 2) It must be an IP of PC where IDE is running. 3) If it will be "direct" connection (from AWS to your PC) then few possible issues: 3.1) Your IP might be changing often so you may need to configure that again 3.2.) You may simply not have a "white" IP or your ISP might be blocking such incoming – LazyOne Sep 24 '17 at 22:46
  • It looks like that may be the case. I'm in a corporate network with hundreds of other machines so it sounds like I'll need to talk to IT to see whether they can open up port 9000 on my local machine on the network. I'll also try this at home to see if that really is the case. – Seline Sep 24 '17 at 22:48
  • 1
    4) therefore it's better to use SSH tunnel -- you establish secure connection to your VPC .. and then xdebug connects to that "local" IP inside PVC and SSH will forward it to your local PC -- will solve #3. You may use DBGp Proxy for this.. but it's not really needed (unless you will have more than 1 dev *debugging at a time*). **In any case** -- always check what xdebug log has to say -- it will tell what IP:port it tries to connect to and if connection was successful or not. – LazyOne Sep 24 '17 at 22:48
  • ohh interesting. How would I set up an SSH tunnel to do that? Do I just do it on the docker container itself? – Seline Sep 24 '17 at 22:51
  • Yes, the xdebug log also confirms that it can't connect: Log opened at 2017-09-24 22:25:05 I: Connecting to configured address/port: 10.22.2.171:9000. W: Creating socket for '10.22.2.171:9000', poll success, but error: Operation now in progress (29). E: Could not connect to client. :-( Log closed at 2017-09-24 22:25:05 – Seline Sep 24 '17 at 22:54
  • No -- SSH tunnel is for connecting from your dev PC to your cloud (if that's possible, of course) .. or to some host that is inside it (but not Docker as it does not really have SSH/it's not needed in Docker-driven setups). if you will install DBGp Proxy ,, then just use it instead I guess (IDE connects to proxy first; then xdebug connects to proxy .. and it will forwatd it to the target IDE). – LazyOne Sep 24 '17 at 22:55
  • I've got DBGp Proxy installed and I'm trying to get it to run. Does my IDE need to be listening for it to run? I'm running it on Docker using: `./pydbgpproxy -d 127.0.0.1:9080 -i 192.168.1.117:9081` (I swapped to port 9080 since I have PHP worker threads listening on 9000 too) When I do this, I get the following error: INFO: dbgp.proxy: starting proxy listeners. appid: 254 INFO: dbgp.proxy: dbgp listener on 127.0.0.1:9080 INFO: dbgp.proxy: IDE listener on 192.168.1.117:9081 ERROR: dbgp.proxy: the debugger could not bind on port 9081 – Seline Sep 24 '17 at 23:08
  • Nvm! I'm an idiot haha, I figured it out. DBGp is running! Now to see if it works :D – Seline Sep 24 '17 at 23:16
  • Just in case: https://confluence.jetbrains.com/display/PhpStorm/Multi-user+debugging+in+PhpStorm+with+Xdebug+and+DBGp+proxy – LazyOne Sep 24 '17 at 23:29
  • Thanks! I've been following that page. Unfortunately, while I've got DGBp Proxy running (I reconfigured my entire Docker container to set it up) and listening on ports 9080 (dbgp itself) and 9081 (ide), my xdebug is still not able to connect to it W: Creating socket for '127.0.0.1:9080', poll success, but error: Operation now in progress (29). E: Could not connect to client. :-( – Seline Sep 24 '17 at 23:39
  • Please see if this article helps http://tarunlalwani.com/post/debugging-php-xdebug-docker/ – Tarun Lalwani Sep 25 '17 at 05:27
  • @Seline Post your solution once you manage to resolve your issue -- it will be useful for others in similar situation. – LazyOne Sep 25 '17 at 20:10
  • I was unfortunately not able to get xdebug to connect to the proxy. I've had to shelve this for now but will hopefully get back to it in the next few weeks – Seline Sep 29 '17 at 20:33

0 Answers0