Docker Php Cli Xdebug



On this post we are setting up a Docker Container for Centos 7 and PHP 7.3 with an installation of Xdebug.

If you compare this Dockerfile with our previous one for PHP 7.3 you will notice that we have included the php-devel package. This is required since we will be using pecl to install Xdebug, which will build, install and load it.
Additionally we will need to install the make package.


You can also download this Dockerfile here

  • While designed for web development, the PHP scripting language also provides general-purpose use. All legacy individual and organizational repository plans expire on their January 2021 billing cycle date.
  • When I added to xdebug.ini: xdebug.clienthost = 172.17.0.1 and xdebug.startwithrequest = yes and ran export PHPIDECONFIG='serverName=localhost' but I don't use Windows/MacOs so I can use host.docker.internal like clienthost. The IP doesn't seem like good idea (docker and change this IP?). Next question - Why it works on web server in browser?? – viko Feb 22 at 21:55.

The only difference from the official Docker PHP images is that, the xdebug plugin is installed, configured and ready to use with modern IDEs like phpStorm. Use from Docker Registry Since all images are based on official Docker PHP images, please check official Docker PHP images documentation how to use them from Docker Registry.


The Dockerfile also updates the /etc/php.ini file, by adding the following xdebug section:


  • Note that we have specified host.docker.internal as the IP address of our host machine, instead of an actual IP address. That is a docker variable that will be translated into the IP address of the machine running the docker container.

Docker Php Cli Xdebug

Create the Docker Image and Container

Now we create the Docker Image.

Docker Php Cli Xdebug

Phpstorm Docker Xdebug Not Working


Then we create the Docker Container.

Notice that we need to indicate the path of our local folder that will be served as the root of the Apache Web Server, which in this example is /path_to/my_website. Replace it with the location of your site's root folder.

Php Xdebug Config


After the Docker Container is created, you can go to the url http://localhost:4000 to open the local website.


Esxi 6 web interface url. To check Xdebug has been correctly installed and configured, open a terminal window into the Docker Container with the following command:


Php Xdebug Remote

Then, on the terminal window inside the container, we will use the php -i instruction to get information about our PHP installation. We will also use the grep utility to display only the information relevant to Xdebug:


Docker Php Cli Xdebug

You will see an output similar to this one (excerpts):


Downloads

Dockerfile

Check the Dockerfile on Github here.

Download the Image from Docker Hub here.