Skip to main content

Updating Xdebug via PECL in DDEV

· 2 min read
Stephan Hochdörfer

For a recent project, I tried to enable Xdebug in our DDEV environment. What worked fine in the past did not work correctly this time. Once Xdebug was active, reloading the page resulted in a HTTP 503 error.

I ran across an issue on GitHub with a similar problem. Apparently, the issue was with Xdebug itself, and according to the GitHub issue, installing the latest version of the Xdebug PHP extension should work fine. It was suggested to add the following line to the .ddev/config.yaml file:

webimage_extra_packages: [php8.1-xdebug]

However, after restarting DDEV the problem still existed. Looking for an alternative solution, I came across a post on StackOverflow explaining how to install PECL extensions in a ddev environment. So, I took that route.

In your project, create a Dockerfile .ddev/web-build/Dockerfile with the following content:

ENV extension=xdebug
SHELL ["/bin/bash", "-c"]
RUN disable_xdebug
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confnew" --no-install-recommends --no-install-suggests build-essential php-pear php${DDEV_PHP_VERSION}-dev
RUN pecl install ${extension}

After restarting DDEV, I enabled xDebug, and this time, it worked without any problems. Problem solved.

You can use the same mechanism to install PECL extensions that are not part of the DDEV distribution or that are not installable via apt-get.