If all XDebug options are displayed with their default/configured values, it works! Start configuring! To know whether XDebug is available, run php -dzend_extension=xdebug -i | grep xdebug. Yeah, it’s just about removing the extension. TL DR: it means that you can do php -dzend_extension=xdebug instead of php -dzend_extension=xdebug.so for UNIX and php -dzend_extension=xdebug.dll for Windows. If you have PHP 7.2+, you can even make your debug-based test scripts cross-compatible with any platform thanks to extension loading by name This echo thing is a trick to force pecl to execute in a “non-interactive” mode, in order to let the Docker image be built automatically with no user interaction (which is not possible). I usually install it in my Docker images by adding a RUN statement with (echo '' | pecl install xdebug). Of course now you have a working Docker setup, but remember that XDebug must be present. I also consider you already installed the Docker plugin for your PHPStorm IDE. I will now consider you have a working PHP + Docker environment. Having a working Docker environmentįirst of all, if we talk about Docker, you may refer to the series of blog posts I wrote about Docker, it might help you. I’m only using it when testing, with PHPUnit or Behat, and that’s perfect: it forces me to write more tests. I have struggled so much in the past and never succeeded in configuring this, and I will probably never do it anyway. ℹ️ Important note: I will not talk about using it in an HTTP context. Sandro Keil is a Senior Software Developer and IT-Consultant and has more than 15 years experience in web development as Full Stack Developer.Here, I’m going to talk about configuring XDebug with PHPStorm and Docker. 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 ![]() ![]() 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 ![]() 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.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |