Skip to content

Instantly share code, notes, and snippets.

@ojhaujjwal
Last active August 13, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojhaujjwal/e36f544fd1209ee20641bf70e2d2147e to your computer and use it in GitHub Desktop.
Save ojhaujjwal/e36f544fd1209ee20641bf70e2d2147e to your computer and use it in GitHub Desktop.
Configure Xdebug with PHPStorm and Docker for Mac

Add the following xdebug.ini in your docker container:

zend_extension=/usr/lib/php/20170718/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=off
xdebug.idekey=debugit
xdebug.remote_host=docker.for.mac.localhost

The most important thing is to set xdebug.remote_connect_back=off and to set xdebug.remote_host=docker.for.mac.localhost . If you want to know why check out this discussion on docker forum.

After that, Configure Docker for Mac integration on PHPStorm.

  1. Go to Preferences -> Build, Execution & Deployment > Docker
  2. Click on + icon somewhere.
  3. Select Docker for Mac
  4. Add path mappings of your container path to local path on Mac.
  5. Click OK.

After that, Add Docker run configuration for the project as

  1. Go to Run > Edit Configurations
  2. Click on + icon somewhere.
  3. Select Docker > docker-compose.
  4. Choose the server that you just created while configuring Docker integration on PHPStorm.
  5. Add the path to the compose file.
  6. If necessary, add services.
  7. Click OK.

After that, Add Debug configuration as

  1. Go to Run > Edit Configurations
  2. Click on + icon somewhere.
  3. Select PHP Remote Debug.
  4. Enter an appropriate name. I choose Xdebug Docker
  5. Check Filter debug connection by IDE key.
  6. Select the docker server.
  7. Add the value debugit(set in xdebug.idekey above) as IDE key(session id).
  8. Click OK.

After that, now start debugging as:

  1. Go to Run > Run
  2. Select the name of Debug configuration. For me, it was Xdebug Docker.
  3. In the toolbar, Click a phone-like icon which says Start listening for PHP Debug connections.

Happy Debugging!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment