
There are several strategies we can use to manage debugging, from stopping execution after dump / print the content of the variable we want to inspect (I still with this more often that I’d like to admit) to more sophisticated tools or web-server modules.
PHPSTORM DOCKER XDEBUG FULL
Sandro Keil is a Senior Software Developer and IT-Consultant and has more than 15 years experience in web development as Full Stack Developer.Debugging, an issue that all developers should live with. Vagrant users can read Vagrant remote PHP & CLI debugging with PHPStorm. Interested in profiling? Read more about profiling. Note that these Xdebug settings also work with a web server like nginx and php-fpm. Conclusionĭocker is a perfect match for PHP development. The prooph Docker PHP build on Docker Hub includes several PHP versions from PHP 5.6 to 7.2 for CLI and PHP-FPM as well. $ docker run -rm -it -volume $(pwd):/app -e PHP_IDE_CONFIG="serverName=application" prooph/php:7.1-cli-xdebug php -d xdebug.remote_host=172.17.0.1
PHPSTORM DOCKER XDEBUG HOW TO
Here is an example how to override the default Xdebug remote_host option. If you are using Docker Machine and VirtualBox, use the IP of the VirtualBox network interface. You can override the default Xdebug configuration with the php -d xdebug.remote_host=172.17.0.1 parameter. Since Docker 1.9, the Docker gateway IP for me is 172.17.0.1. To check your Docker gateway IP run the command $ ifconfig and look for the docker0 network adapter. #!/bin/bashĭocker run -rm -it -volume $(pwd):/app -e PHP_IDE_CONFIG="serverName=application" prooph/php:7.1-cli-xdebug php this file executable with chmmod +x ~/bin/docker-xdebug.sh and you can start a new Xdebug session with: $ docker-xdebug Īt default, Xdebug's remote host is configured with xdebug.remote_host=172.17.0.1, but it can be different to your Docker gateway IP address. Create a file docker-xdebug.sh in your ~/bin folder and put the following lines to it. It is recommended to create a simple bash file which works with every project. It's important that your path mapping has the name application and to pass the environment variable PHP_IDE_CONFIG with the name of the server. $ docker run -rm -it -volume $(pwd):/app -e PHP_IDE_CONFIG="serverName=application" prooph/php:7.1-cli-xdebug php You have configured your path mappings and enabled listen for incomming Xdebug connections, then you can start the container with the following command from the root of your project. Your project files will be mounted there. Fill out the name with application and set /app to the absolute path mapping on the server of the root folder. Open the settings File -> Settings -> Languages & Frameworks -> PHP -> Server and enable path mappings. If you run this Docker container and listen to incoming connections, it stops on the activated breakpoints. xDebug is automatically enabled in the configuration. PhpStorm uses the serverName to determine the right server. Important is the server name application. In the meantime, you can configure your IDE path mappings. Pull the PHP Xdebug image from Docker HubĮnsure Docker is installed and then run the following command: $ docker pull prooph/php:7.1-cli-xdebug

PHPSTORM DOCKER XDEBUG CODE
This image can also be used to generate the code coverage with PHPUnit. You have only to set your path mappings in your IDE.

It's quite easy, because I have created a several Docker PHP Xdebug Images on GitHub. Now it's time to throw away var_dump and to use Xdebug for PHP Docker container. I use Docker for development and for my website too.
