Docker Xdebug Php



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

  1. Docker Xdebug Php-fpm
  2. Php Docker Xdebug Phpstorm
  3. Docker Xdebug Phpstorm Windows

Docker Xdebug Php-fpm

Php

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.

Before Docker, Xdebug was relatively straightforward to configure on a platform, in that it was a new set of the php.ini parameters – you’d either just edit the existing php.ini, or load in a custom ini or override. Instruct XDebug to connect to host.docker.internal for command line execution or whenever “connect back” is not possible. Set PHPIDECONFIG env variable to serverName=localhost. This will tell your PhpStorm which server configuration to use. See next step for details.


You can also download this Dockerfile here


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.

FreeXdebug

Create the Docker Image and Container

Now we create the Docker Image.


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.


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


To check Xdebug has been correctly installed and configured, open a terminal window into the Docker Container with the following command:


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:

Php Docker Xdebug Phpstorm


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


Downloads

Dockerfile

Check the Dockerfile on Github here.

Docker Xdebug Phpstorm Windows

Download the Image from Docker Hub here.