Xdebug Support: PHP debugging

@sonicviz and @jamesgreenblue
I managed to make it work!

My xdebug.ini looks like this:
[xdebug]
zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003

Then, in my PHPStorm, I have used PHP Web Page template to create a new Debug Configuration.
Point your server to the domain you are working on
Default port 80 running Xdebug.

I’m using Chrome with Xdebug helper - Chrome Web Store extension to activate it for the website I’m working on.

For me, it works like charm.

Took me some time to figure it out, but it works.
Hope it helps!

2 Likes

Thank you for sharing @nemanjac !!

I tried all the above on windows and can’t get it to work.
Xdebug 3 is also different from xdebug 2, though I used your xdebug 3 config.

Gone back to using http://devilbox.org/ because I can use XDebug as well as Elasticsearch locally.

I use VSCode, much prefer it over PHPStorm.

There might be minor differences between 2 and 3 in the matter of config.
If you are using PHPStorm you can easily test your XDebug config, and you can add an XDebug log on the server too, to figure out what is causing issues.

By all means, if you do have the functional solution that fits your needs, it’s great.
I just wanted to share as there were questions about how to get it to work.

Cheers

Hi @nemanjac - we are using Visual Studio Code which appears to be a little bit harder to troubleshoot when it comes to client configuration. Do you have any advice here for the settings to use?

I took another stab at it and got DevKinsta Xdebug working. I used my XDebug 3 config from Devilbox.

The following is for an example WordPress install, testing by breakpointing the index.php in the root directory of “YourSiteName”. Running on PHP 7.4, change as appropriate for other versions.

Pull up a windows terminal, then:

Install XDebug into DevKinsta Php if needed:
docker exec devkinsta_fpm bash -c “apt-get update;apt-get -y install php7.0-xdebug php7.1-xdebug php7.2-xdebug php7.3-xdebug php7.4-xdebug php8.0-xdebug”
docker restart devkinsta_fpm

then

docker exec -it devkinsta_fpm bash
cd /etc/php/7.4/fpm/conf.d
nano 20-xdebug.ini

Edit it to:
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.idekey = VSCODE
xdebug.client_host = host.docker.internal
xdebug.log = /var/log/php/xdebug.log

save, exit back to windows terminal prompt

docker restart devkinsta_fpm

.vscode launch.json

{
  "version": "0.2.0",
  "configurations": 
[
    {
      "name": "Xdebug for Project YourSiteName",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/www/kinsta/public/YourSiteName": "${workspaceRoot}"
      }
    },

    {
      "name": "Launch currently open script",
      "type": "php",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}",
      "port": 9003
    }
  ]
}
3 Likes

@jamesgreenblue
I did some test last night but @sonicviz beat me to it :smiley:

I think I was missing xdebug.idekey = VSCODE as I don’t VSCode, but PHPStorm.

@sonicviz
due to some performance issues with docker (might be M1 related only) I commented out the log file.
It was impacting performance a lot. So after you get it working, you might want to comment it out.

No worries, nice to see it’s working for some major IDE’s now.

@nemanjac I see you are also a Codeable dev :vulcan_salute:

Yeah, it took some work, but we “hacked” it :slight_smile:

I’m thinking of making set of bash scripts that one call pull in and setup what is needed, change configuration etc…

Greetings fellow expert :vulcan_salute:

Hi @michael

I just wanted to add my voice to the chorus of “any ETA on this?”, as it cannot be overstated how critical xdebug is for any kind of local development environment for a PHP project. Some would say it’s pretty much the entire point of having a local sandbox.

Even if you can’t get a fully integrated Just Push A Button solution going soon, detailed instructions in the KB for PHPStorm and VSCode would go a long way to easing the pain and time.

To anyone else using PHPStorm, the only thing I had to do beyond the excellent community advise in this thread was to add path mappings in Settings → PHP → Servers for both servers (80 and 443), mapping /www/kinsta/public/SITENAME to C:\Users\MYNAME\DevKinsta\public\SITENAME.

– hugh

2 Likes

Yes, I noticed this yesterday.
This problem came up with last update. I was on call with another expert @Codeable where we were trying to debug a problem, and noticed that mapping is now necessary for this to work properly.

Thank you for pointing this out, as I had idea to update my post, but forgot.

Not yet I’m afraid but the devs are definitely aware of the strong support for this feature.

2 Likes

This worked for me too on MacOS

Huge thank you @sonicviz for the consolidated instructions :green_heart:

Hi all, I want just to share my steps to make this working with PhPStorm and Linux Mint

first, install xdebug

docker exec devkinsta_fpm bash -c 'apt-get update;apt-get -y install php7.0-xdebug php7.1-xdebug php7.2-xdebug php7.3-xdebug php7.4-xdebug php8.0-xdebug'

Then I added these lines on my xdebug.ini

zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.client_host=172.19.0.1
xdebug.client_port=9003

and then I restart the container

docker exec -it devkinsta_fpm bash

Thank you all!

3 Likes

I really hope to see XDebug in DevKinsta soon without the manual setup/configuration.

1 Like

I’m trying to figure out how to get this all set up. I’m having no luck. I added the following the xdebug.ini

zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.client_host=172.19.0.1
xdebug.client_port=9003
xdebug.start_with_request = yes
xdebug.idekey = PHPSTORM
xdebug.log = /var/log/php/xdebug.log

I can’t get anything to work. Is there a correlating setting I am missing? I have the xdebug extension for chrome installed and running. I found the settings for it and it is looking for the PHPSTORM IDE key. I have PHPStorm listening and I even used the built in validation tool and it all checked out. So I’m not sure why my breakpoints aren’t catching.

Any help is much appreciated. Thank you.

What am I missing here?

Hi @robruiz - did you see the guide I’ve posted here?

I’m not familiar with the dialog in your screenshot. I’ve configured Xdebug via “PhpStorm > Preferences… > PHP > Debug”

Also, I do not use an IDE key, as I enable or disable debugging via the Chrome extension. Generally, the IDE key caused problems for me in the past, so I never use it. I always enable or disable Xdebug in the whole environment instead of using IDE keys/session ids.

Aside from that, I recommend clicking the “Validate” link in your “Pre-configuration” section. Possibly, you will get some additional tips from PhpStorm on what’s failing.

I did not stumble upon this. Thank you so much for pointing it out. I’m gonna run through this and give it a try. Thanks!

Any updates on this? It’s been a year and still nothing.

I got a notice that port 9003 was already in use. I didn’t want to debug it, so I just changed it to 9999 in xdebug.ini and launch.json. And it worked! Awesome! Thanks!

1 Like