lando/platformsh

xdebug with phpstorm

gcalex5 opened this issue · 4 comments

Are there any docs or guides available for getting the platformsh lando recipe working with xdebug and phpstorm that someone could point me at?

Had seen this one, and was able to verify that the xdebug extension was loading. However, wasn't able to pick up a connection with phpstorm using that.

Have also tried something like this with no luck in my .lando.yml(phpstorm is configured to localhost with the root of project and web directory mapped to app and /app/web respectively):

name: <name>
recipe: platformsh
config:
  id: <id>
  overrides:
    app:
      runtime:
        extensions:
          - redis
          - xdebug
      php:
        # XDEBUG 3
        xdebug.mode: debug
        xdebug.max_nesting_level: 1024
        xdebug.client_port: 9003
        xdebug.show_exception_trace: 0
        xdebug.collect_params: 0
        xdebug.remote_autostart: 1
        xdebug.start_with_request: yes

@gcalex5 Have you been able to verify that the settings you specified in the .lando.yml are even taking effect? I'm also trying to get it working and it doesn't seem like any of the overridden xdebug vars are actually making a difference.

name: <name>
recipe: platformsh
config:
  id: <id>
  overrides:
    app:
      runtime:
        extensions:
          - xdebug
          - redis
          - apcu
      php:
        xdebug.mode: debug
        xdebug.client_port: 9003
        xdebug.client_host: 172.17.0.1
        xdebug.start_with_request: yes
        xdebug.idekey: lando
        xdebug.log: /tmp/php-xdebug.log

So I found this issue #51 and the way they setup the .lando.yml actually seems to work, I'll keep playing with it. Note that I had to enable the xdebug extension in my .platform.app.yaml.

Updated .lando.yml:

name: <name>
recipe: platformsh
config:
  id: <id>
  variables:
    app:
      php:
        xdebug.mode: debug
        xdebug.client_port: 9003
        xdebug.client_host: 172.17.0.1
        xdebug.start_with_request: yes
        xdebug.idekey: lando
        xdebug.log: /tmp/php-xdebug.log

Okay got it working for page requests with PHPStorm:

# .lando.yml
name: <name>
recipe: platformsh
config:
  id: <id>
  variables:
    app:
      php:
        xdebug.mode: debug
        xdebug.client_port: 9003
        xdebug.client_host: 172.17.0.1
        xdebug.start_with_request: yes
        xdebug.idekey: lando
        xdebug.log: /tmp/php-xdebug.log
# excerpt in .platform.app.yaml
...
variables:
  php:
    ...
  env:
    XDEBUG_CONFIG: "client_host=172.17.0.1"
    PHP_IDE_CONFIG: serverName=lando

runtime:
  extensions:
   ...
    - xdebug
...

In PHPStorm I have a Debug configuration setup with a type of PHP Web Page and using a Server configuration named lando that has path mappings setup from my project root to the /app within the app container.

Just to explain a few other things:

I use a client_host of 172.17.0.1 since that represents the host's IP from within the app container on a Linux machine (on Windows and Mac you should be able to use host.docker.internal).

Not 100% sure on why this is but I had to specify client_host twice as only specifying it in the variables config didn't seem to remove the default value.

The PHP_IDE_CONFIG needs to have the same name as whatever you specify for your PHPStom server configuration, doesn't have to be lando.

I've burnt a few hours trying to get this to work with no luck, what I find strange is that this all works with Drupal9 recipe following the lando documentation so why not adopt the same process?

If you add xdebug to platform.app.yaml wont't that run xdebug on the production dreployemnt and thus cause performance issues?

I'd got back to the Drupal9 recipe but I can't get the DB to export.

I'm mot sure what benefits the recipe has over the standard Drupal one.