Solved - PHPStorm xDebug remote Debug not working

Solved - PHPStorm xDebug remote Debug not working

Every PHP developer should be familiar with remote Debugging via xDebug or Zend Debug but how to Debug not working Xdebug environment? Read our article.

Xdebug remote debug will connect to remote_host on default port 9000, where your PHPStorm should listen.

Example xDebug config

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.remote_log=/var/www/html/xdebug.log
xdebug.remote_host=dockerhost
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_timeout=2000
xdebug.cli_color=0
xdebug.profiler_enable=0
xdebug.profiler_output_dir=/var/www/html/var/profiler/
xdebug.remote_handler=dbgp
xdebug.remote_mode=req

xdebug.remote_port=9000
xdebug.idekey=PHPSTORM

xdebug.profiler_enable_trigger = 1

xdebug.collect_includes = 0
xdebug.coverage_enable = 0

xdebug.default_enable = 0

Where dockerhost is one of PHPStorm listening IPs from Automatically detect IDE IP

My dev setup is PHP in Docker, so I use docker-compose.yaml with extra_hosts configuration and expose

    expose:
      - 9000
    extra_hosts:
      - "dockerhost:${XDEBUG_HOST_IP}"
    env_file: .env

In my .env file I setup XDEBUG_HOST_IP=192.168.141.81

How to test, if xDebug will work? Open PHPStorm. Exec into your running PHP environment - in my case - docker-compose exec php shand run nc command.

If it shows open, you will be ok. If not, try to use another IP from PHPStorm Automatically detected IP (PHPStorm - Settings - Languages & Frameworks - PHP - Debug)

docker-compose exec php sh
nc -vz dockerhost 9000
> dockerhost (192.168.141.81:9000) open

And voila! It works!