Skip to content

Instantly share code, notes, and snippets.

@coleca
Last active May 25, 2016 00:16
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 coleca/c227543fbed515e4eb4c058a7455c581 to your computer and use it in GitHub Desktop.
Save coleca/c227543fbed515e4eb4c058a7455c581 to your computer and use it in GitHub Desktop.

Using XDebug with Docker for Mac and IntelliJ or PHPStorm

  1. Add the following into your Dockerfile

    RUN yes "" | pecl install xdebug                                                             && \
    	echo "zend_extension="$(find / -name xdebug.so) > /etc/php5/fpm/conf.d/xdebug.ini && \
    	echo "xdebug.remote_enable = on" >> /etc/php5/fpm/conf.d/xdebug.ini                      && \
        echo "xdebug.remote_host = 10.254.254.254" >> /etc/php5/fpm/conf.d/xdebug.ini            && \
        echo "xdebug.remote_port = 9000" >> /etc/php5/fpm/conf.d/xdebug.ini                      && \
    	echo 'xdebug.idekey = "INTELLIJ"' >> /etc/php5/fpm/conf.d/xdebug.ini                     && \
        echo 'xdebug.remote_log = /var/log/xdebug_remote.log' >> /etc/php5/fpm/conf.d/xdebug.ini && \
    	touch /var/log/xdebug_remote.log && chown www-data:www-data /var/log/xdebug_remote.log
    
  2. Setup an alias for localhost on your Mac

    • In terminal.app run the following command: sudo ifconfig lo0 alias 10.254.254.254
  3. Configure PHPStorm / IntelliJ Preferences

    • Press ⌘, (Command - comma) to open the Preferences pane

    • Navigate to Languages & Frameworks -> PHP

    • Make sure a PHP interpreter is set Set Interpreter

    • If not, press the ... button and setup an interpreter based on the PHP installation on your Mac Create Interpreter

    • Navigate to Languages & Frameworks -> PHP -> Debug

    • Make sure these settings are checked. Note: that Break at first line in PHP scripts is optional Debug Settings

    • Navigate to Languages & Frameworks -> PHP -> Servers

    • Setup new server as shown in the screenshot below taking note to add in the mapping between your local project and the directory from the container. PHP Server

  4. Configure PHPStorm / IntelliJ Project Debug Settings

    • Click the Run/Debug Configuration dropdown button to setup a new debug config, or choose "Edit Configurations..." from the "Run" menu
      Debug Menu

    • Click the + button to create a new config

    • Choose "PHP Remote Debug" from the dropdown menu

      Add Debug Config

    • Setup the config according to the screenshot below:
      Debug Config

    • Make sure that the Server is set to the server you created in step 3

    • Make sure that the "Ide key" is set to INTELLIJ (or whatever you have xdebug.idekey set to in your Dockerfile)

  5. Make sure your Docker container is running with docker run or docker-compose up -d

  6. Start the debugger by pressing the green debug toolbar button or press CTRL-D
    Debug Start

  7. Submit your request, or browse to a page on localhost:8080

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