How can I install Xdebug on DDEV for PHP 8.3 before it's ready in a release?

586 Views Asked by At

Edit 2023-12-08: The upstream issues are resolved. For DDEV v1.22.5, just add this to .ddev/config.yaml:

webimage_extra_packages: [php8.3-xdebug]

For versions after v1.22.5, nothing needs to be done.


DDEV v1.22.5 has support for PHP 8.3.0, but it does not yet have xdebug. How can I get xdebug before it's released in the upstream repositories?

2

There are 2 best solutions below

0
On BEST ANSWER

Edit 2023-12-08: The upstream issues are resolved. For DDEV v1.22.5, just add this to .ddev/config.yaml:

webimage_extra_packages: [php8.3-xdebug]

For versions after v1.22.5, nothing needs to be done.


Leaving the discussion below because it's great for any needed PECL package.

You can use pecl in a custom .ddev/web-build/Dockerfile to install any PECL extension.

Add this .ddev/web-build/Dockerfile to your project and ddev restart:

# Specify the extension we'll build
ENV extension=xdebug
SHELL ["/bin/bash", "-c"]
RUN disable_xdebug
# Install the needed development packages
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
# The "echo" below just forces accepting the "automatic" configuration, the same as hitting <RETURN>
RUN pecl install ${extension}
# Assuming the extension is already installed in web container in php8.2 we can just copy its configuration
RUN cp /etc/php/8.2/mods-available/${extension}.ini /etc/php/${DDEV_PHP_VERSION}/mods-available/

After it starts up (it takes a little bit to build the image),

$ ddev xdebug # enable xdebug
$ ddev php --version
PHP 8.3.0 (cli) (built: Nov 25 2023 14:38:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.0, Copyright (c), by Zend Technologies
    with Xdebug v3.3.0, Copyright (c) 2002-2023, by Derick Rethans

This can be adapted pretty easily for almost any extension in PECL.

Resources:

0
On

Thanks @rfay !

What I'm about to say is more of a comment than an answer, but I'm writing it here for readability.

Based on your answer, I was able to add the 3 extensions that are still temporarily missing for PHP 8.3 (xdebug, redis and memcached) using a Dockerfile.83missing file with the following content:

SHELL ["/bin/bash", "-c"]
RUN disable_xdebug
# Install the needed development packages
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 zlib1g-dev libmemcached-dev

# X-debug
# The "echo" below just forces accepting the "automatic" configuration, the same as hitting <RETURN>
RUN echo | pecl install xdebug
# Assuming the extension is already installed in web container in php8.2 we can just copy its configuration
RUN cp /etc/php/8.2/mods-available/xdebug.ini /etc/php/${DDEV_PHP_VERSION}/mods-available/

# Redis
RUN echo | pecl install redis
RUN cp /etc/php/8.2/mods-available/redis.ini /etc/php/${DDEV_PHP_VERSION}/mods-available/
RUN ln -s "/etc/php/${DDEV_PHP_VERSION}/mods-available/redis.ini" "/etc/php/${DDEV_PHP_VERSION}/cli/conf.d/20-redis.ini"

# Memcached
RUN echo | pecl install memcached
RUN cp /etc/php/8.2/mods-available/memcached.ini /etc/php/${DDEV_PHP_VERSION}/mods-available/
RUN ln -s "/etc/php/${DDEV_PHP_VERSION}/mods-available/memcached.ini" "/etc/php/${DDEV_PHP_VERSION}/cli/conf.d/20-memcached.ini"

Thanks again