With Xdebug installed and enabled, we need to enable step debugging.
To do that, create the two configuration files: docker/php/conf.d/xdebug.ini
and docker/php/conf.d/error_reporting.ini
; and the paths if you don’t have the directory structure set up yet.
To save some time, you can use the following commands to do so.
1
2
3
| mkdir -p docker/php/conf.d
touch docker/php/conf.d/xdebug.ini
touch docker/php/conf.d/error_reporting.ini
|
In docker/php/conf.d/xdebug.ini
, add the following configuration to configure Xdebug.
1
2
3
4
5
6
| zend_extension=xdebug
[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
|
Here’s what the settings do:
-
mode This setting controls which Xdebug features are enabled.
We’ve set develop
to enable development aids, such as getting better error messages, and debug
to enable step debugging.
-
client_host This setting tells Xdebug the IP address or hostname of the machine that is running your text editor or IDE.
-
start_with_request This setting determines whether a function trace, garbage collection statistics, profiling, or step debugging are activated at the start of a PHP request. Setting it to yes
instructs Xdebug to always initiate a debugging session.
Then, in docker/php/conf.d/error_reporting.ini
, add the following configuration, to enable full error reporting.
Always good to know what’s going wrong, if and when it does.
Then, in the php
service definition in docker-compose.yml
, add the following two entries to the volumes
element.
1
2
| - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
|
With the ini files created and docker-composer.yml
updated, to have the php
container make use of them, restart and rebuild it by running the following command.
1
| docker-compose up -d --build php
|
The --build
flag builds images before starting containers.
It’s essential to use this flag because without it the changes that we made in docker/php/Dockerfile
won’t take effect.
Join the discussion
comments powered by Disqus