Ultimate Docker on OSX collection - debug PHP application

With IntelliJ IDEA

PHP Docker debugging:

See this link to install xdebug:

Configure your IDE, listen on income debug request, create php server, debug session:

Restart your docker with docker-compose restart nhweb

The Steps:

  1. Get in to your docker running container:
1
2
3
4
5
6
7
8
9
10
11
docker exec -it container_name /bin/bash

pecl install xdebug
docker-php-ext-enable xdebug
sed -i '1 a xdebug.remote_autostart=true' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_mode=req' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_port=9000' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_host=127.0.0.1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
  1. Restart your container:
1
2
# Docker composer
docker-compose restart nhweb
  1. In Intellij/PHPStorm go to: Languages & Frameworks > PHP > Debug > DBGp Proxy and set the following settings:
  • Host: your IP address
  • Port: 9000
  1. Add remote debug in your Run/Debug Configuration

    • Add server, map directory
  2. Debug it to start the debug session.

  3. Put a breakpoint in your index.php, open the browser.