1

I'm using Wp-env to develop a plugin as it's a pretty robust wrapper for Docker that includes phpunit and xdebug.

However, I have been struggling to get xDebug working.

  • From my_plugin directory run wp-env start... await build
  • set .vscode/launch.json as per docs:
{
  "name": "Listen for XDebug",
  "type": "php",
  "request": "launch",
  "port": 9003,
  "pathMappings": {
    "/var/www/html/wp-content/plugins/my_plugin": "${workspaceFolder}/"
  }
}
  • run wp-env start --xdebug
  • open main plugin file and add breakpoint in VS Code and try to Run and Debug
  • Result: "PHP Fatal error: Uncaught Error: Call to undefined function plugin_dir_path" (and if I add !defined( 'ABSPATH' ) die(), it is tripped.)

I'm new to this tool so expecting it's a newbie error. Seems like xDebug should be starting at the Wordpress entrypoint, but isn't.

There is one more item of note, though. In wp-env logs:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(, referer: http://localhost:8888

1 Answer 1

0

What the issue ended up being is embarrassing!

I had used the xdebug configuration as the entire launch.json file:

{
  "name": "Listen for XDebug",
  "type": "php",
  "request": "launch",
  "port": 9003,
  "pathMappings": {
    "/var/www/html/wp-content/plugins/my-plugin": "${workspaceFolder}/"
  }
}

As opposed to the correct:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/html/wp-content/plugins/my-plugin": "${workspaceFolder}/"
      }
    }
  ]
}

Older and wiser!

For other debuggers, this was my path:

The output of adding to index file: xdebug_info(); includes:

[Step Debug] Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).

and

[Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

Within the docker container:

/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

contains expected: zend_extension=xdebug

In the host, OS X computer:

$ nslookup host.docker.internal
Server:     2001:578:3f::10
Address:    2001:578:3f::10#53

** server can't find host.docker.internal: NXDOMAIN

And in the container, /etc/hosts:

127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.25.0.5  9cf0413e6c4f

Also /etc/resolv.conf:

nameserver 127.0.0.11
options ndots:0

On the guest, installed apt-get update && apt install dnsutils, for

# nslookup host.docker.internal
Server:     127.0.0.11
Address:    127.0.0.11#53

Non-authoritative answer:
Name:   host.docker.internal
Address: 192.168.65.2

Adding this to my (host computer) hosts file: 127.0.0.1 host.docker.internal did not help.

Wait a minute?

Why does VS Code keep telling me there isn't a launch.json file, then opening it when I direct it to create one? And... see above. : )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.