Bobcares

Docker Compose Xdebug extension | Tutorial

by | Jun 14, 2022

Docker Compose XDebug extension comes in handy to debug PHP code. Read on to find out to enable and set it up. 

At Bobcares, we offer solutions for every query, big and small, as a part of our Docker Support Services.

Let’s take a look at how our Docker Support Team is ready to introduce customers to the Docker Compose XDebug extension.

How to enable and set up Docker Compose XDebug

XDebug is responsible for helping us debug our PHP code. Moreover, there is a separate container to handle requests from XDebug in the Docker environment. In fact, we can use this container and enable XDebug to debug the PHP code without impacting Adobe Commerce on the cloud infrastructure project configuration. Let’s take a look at how to use the extension:

  1. To begin with, add the following code to our PHP Dockerfile:
     RUN yes | pecl install xdebug \
        && echo "zend_extension=$(find $(php-config --extension-dir) -name xdebug.so)" \
             > /usr/local/etc/php/conf.d/xdebug.ini
  2. Next, add the following environment variables to docker-compose.override.yaml:  Docker Compose XDebug
    services:
      your_php_app_service:
        environment:
          XDEBUG_ENABLED: 1
          XDEBUG_REMOTE_AUTOSTART: 1
          XDEBUG_MAXNESTING_LEVEL: 1000
          XDEBUG_REMOTE_CONNECT_BACK: 1
          XDEBUG_REMOTE_HOST: host.docker.internal
          PHP_IDE_CONFIG: serverName=localhost
  3. Then, we have to enable the Docker Compose XDebug extension.
  4. After that, enable the automatic start option for every request.
  5. Next, we have to increase the maximal function nesting value.
  6. Then, instruct XDebug to connect to the IP where the web request originated. We also have to set up Docker Compose XDebug extension to connect to host.docker.internal for command-line execution.
  7. Now it is time to modify the PHP_IDE_CONFIG env variable to serverName=localhost.
  8. Next, add a new server by navigating to Languages and Frameworks > PHP > Servers :
      • Name: localhost
      • Host/Port: host and port we will use to open the local website
      • Debugger: Xdebug
      • Use path mappings: yes

    Additionally, configure the path mapping as per the source code volume mount in the docker-compose.yaml file.

[Need assistance with a different issue? We are available 24/7.]

Conclusion

In a nutshell, our skilled Docker Support Engineers at Bobcares introduced us to the Docker Compose XDebug extension.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.