Add a new CLI interpreter by clicking. Click the +on the top left and add a new Docker configuration. Select Docker Compose and the php service, then use the. Xdebug is an extension for debugging your PHP code. Magento Cloud Docker provides a separate container to handle Xdebug requests in the Docker environment. Use this container to enable Xdebug and debug PHP code in your Docker environment without affecting your. Next, docker-compose stop and docker-compose start (or if you don’t use docker-compose then it should be docker container stop and docker container start respectively) to restart the container and make the changes take effect. Finally, verify that the PHP Debug section in your PHPStorm setting to make sure that the Xdebug port there points to the same port you defined in the xdebug.ini file. I’ve be searching a days to a solution but not success. I installed Xdebug 2.5.5 in my Docker container and added it to my php.ini as follow. Xdebug zendextension = '/usr/local.
I use Docker for development and for my website too. Now it's time to throw away var_dump
and to use Xdebug for PHP Docker container. It's quite easy, because I have created a several Docker PHP Xdebug Images on GitHub. You have only to set your path mappings in your IDE. This image can also be used to generate the code coverage with PHPUnit. Ok, let's go step by step.
Ensure Docker is installed and then run the following command:
This can take some minutes. In the meantime, you can configure your IDE path mappings.
Important is the server name application. PhpStorm uses the serverName
to determine the right server. xDebug is automatically enabled in the configuration. If you run this Docker container and listen to incoming connections, it stops on the activated breakpoints. Open the settings File -> Settings -> Languages & Frameworks -> PHP -> Server
and enable path mappings. Fill out the name with application and set /app to the absolute path mapping on the server of the root folder. Your project files will be mounted there.
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.
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. It is recommended to create a simple bash file which works with every project. Create a file docker-xdebug.sh
in your ~/bin folder and put the following lines to it.
Make this file executable with chmmod +x ~/bin/docker-xdebug.sh
and you can start a new Xdebug session with:
Don't expose the Xdebug port 9000
At 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. To check your Docker gateway IP run the command $ ifconfig
and look for the docker0 network adapter. Since Docker 1.9, the Docker gateway IP for me is 172.17.0.1. You can override the default Xdebug configuration with the php -d xdebug.remote_host=172.17.0.1
parameter. If you are using Docker Machine and VirtualBox, use the IP of the VirtualBox network interface. Here is an example how to override the default Xdebug remote_host option.
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 is a perfect match for PHP development. Note that these Xdebug settings also work with a web server like nginx and php-fpm. Interested in profiling? Read more about profiling.
Vagrant users can read Vagrant remote PHP & CLI debugging with PHPStorm.
Do you use PhpStorm and have you ever wondered what all those fancy debugging features were? Or could you just not get Xdebug running in Docker or your Vagrant machine? Wonder no more!
In this guide I will guide you through
You can follow along with the xdebug-example GitHub repository I have used throughout this guide.
Xdebug is a PHP extension developed by Derick Rethans for debugging using the DBGp protocol. Xdebug is the only debugging tool to implement the DBGp protocol. If you’re on Linux and use PECL, you can use the following command:
If you’re on Windows or macOS or do not use PECL, you can follow the installation guide that can be found on the official website here.
After you’ve successfully installed Xdebug, you’re ready to configure it. Preferably create a file named xdebug.ini
in /etc/php.d/
or /etc/php/conf.d
or something else specific to your distribution or add the following to your php.ini
:
With zend_extension
we load the PHP extension we installed. If you’ve installed PHP extensions before, you may be wondering why you have enabled other extensions with just extension=x.so
. This is because certain Xdebug features, such as step debugging, require zend. The path might be different for you depending on how you installed it.
With xdebug.remote_enable
we enable the debugging features of Xdebug to be debugged from a remote location.
With xdebug.remote_autostart
Xdebug will try to automatically debug every time you run anything in PHP. Normally you’d have to set a certain HTTP header when doing a HTTP request or add a certain PHP command line flag to your php
command from the terminal. With this enabled you don’t have to set any HTTP header or command line flag.
If you’re following this guide whilst your application runs in Docker or Vagrant, you’ll need to include the xdebug.remote_host
configuration. With xdebug.remote_host
you tell Xdebug to connect to a certain host when debugging. By default this is localhost
but for Docker you need the default gateway which is aliased to host.docker.internal
or for Vagrant 10.0.2.2
.
Once you’re done configuring, restart apache, nginx, php-fpm or whatever you use and lets start debugging!
If you’re running your PHP code locally, there’s no need to configure anything in PhpStorm. If you’re running things in Docker or Vagrant, you need to setup the path mapping first. Withouth the path mapping PhpStorm wouldn’t debug anything because the file paths wouldn’t match.
Open the settings window and browse to Languages & Frameworks > PHP > Servers. Add a new server pointing to the publicly accessible host and port. If you’re following along with the mtricht/xdebug-example
repository from GitHub, for Vagrant this would be host 127.0.0.1
and port 8001
. Check the Use path mappings
checkbox and map the paths. For my repository and Vagrant this would be:
Once set, you’re ready to debug! First start listening for debugging connections on the top right:
Next you can either set a breakpoint (by clicking on the left side of a line) or break at the first line:
Once you’ve chosen one, it’s time to finally start debugging! Run the code where you set a breakpoint, through either a HTTP request or running a console command, and you’ll see a window pop up on the bottom:
Congratulations, you’re now debugging with Xdebug in PhpStorm! You should try to familiarize yourself with all the buttons PhpStorm has to offer. The most important ones are the arrow buttons on the top. Good luck!