Skip to content

Instantly share code, notes, and snippets.

@tallsam
Forked from jehaby/README.md
Created December 1, 2016 04:43
Show Gist options
  • Save tallsam/aab6632d12a3a880501fc8003c78eda5 to your computer and use it in GitHub Desktop.
Save tallsam/aab6632d12a3a880501fc8003c78eda5 to your computer and use it in GitHub Desktop.
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
  1. Get you local IP address (ip -o -4 addr list ${MY_NETWORK_INTERFACE:-eth0} | awk '{print $4}' | cut -d/ -f1)
  2. Start your container with the following environment variables: XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}"
  • Simple docker run: docker run -e XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}" your-image

  • With docker-compose:

    # docker-compose.yml
    foo:
      build: path/to/Dockerfile
      environment:
        XDEBUG_CONFIG: "remote_host={{YOUR_IP_ADDRESS}}"
        PHP_IDE_CONFIG: "serverName=my.local"
  1. In Intellij/PHPStorm go to: Languages & Frameworks > PHP > Servers > and set the following settings:

  • Name: name of your server, should be equal to value in PHP_IDE_CONFIG variable

Then you're all set and can start listening for PHP Debug connections from your IDE.

Happy debugging!

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