Xdebug + PHPSTORM + DOCKER

Nothing beats the feeling of seeing run time values while debugging PHP.

Final result

In a “recent” project I had to debug PHP 5.4 on a docker machine.

Using vardump() like in old days was no fun ET ALL!!

It took me some time but I finally was xdebugging PHP on the host PHPSTORM.

Coming to the secret sauce, there are couple of important things on Dockerfile and docker-compose.yml files

  1. EXPOSE xdebug port on Dockerfile, I have it as, EXPOSE 9001
  2. expose the same on docker-compose.yml , I have it as

expose:
- "9001"

3. My xdebug.ini


zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_autostart=0
xdebug.idekey=PHPSTORM
xdebug.remote_host={{hostname, more on this below}}
xdebug.remote_port=9001
xdebug.remote_mode=req
xdebug.remote_log=/var/log/xdebug.log

hostname should be the IPv4 address under Wireless LAN adapter Wi-Fi of ipconfig command on windows.

4. Enter PHPSTORM and we have few more settings to tinker around

SETTINGS->SERVERS, PHPSTORM doesn't show the port number but its 9001
YAYY!

This is mostly self note kind of post,but since I couldn't find a decent solution on internet, I decided to do some write up for people like me looking to make xdebug work on phpstorm from docker.