6

I am trying to install Xdebug with Docker and PhpStorm but when I put the code in Dockerfile, an error occurs.

Code:

FROM php:7.1-fpm
# Install selected extensions and other stuff
RUN apt-get update \
    && apt-get -y --no-install-recommends install  php-xdebug \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \ && echo "zend_extension=/usr/lib/php/20160303/xdebug.so" > /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.remote_handler=dbgp" >> /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.remote_port=9000" >> /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.remote_autostart=on" >> /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /etc/php/7.1/mods-available/xdebug.ini \
    && echo "xdebug.idekey=docker" >> /etc/php/7.1/mods-available/xdebug.ini

Error:

E: Package 'php-xdebug' has no installation candidate
/bin/sh: 1: cannot create /etc/php/7.1/mods-available/xdebug.ini: Directory nonexistent
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get update     && apt-get -y --no-install-recommends install  php-xdebug     && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*     && echo "zend_extension=/usr/lib/php/20160303/xdebug.so" > /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.remote_enable=on" >> /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.remote_handler=dbgp" >> /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.remote_port=9000" >> /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.remote_autostart=on" >> /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.remote_connect_back=0" >> /etc/php/7.1/mods-available/xdebug.ini     && echo "xdebug.idekey=docker" >> /etc/php/7.1/mods-available/xdebug.ini' returned a non-zero code: 2
4
  • what's the base image? Commented Sep 13, 2019 at 14:44
  • Dockerfile: /site/php/ Docker-Compose: /site/docker-compose.yml Commented Sep 13, 2019 at 14:45
  • sorry, I mean, can you add the FROM in your Dockerfile? Commented Sep 13, 2019 at 14:46
  • FROM php:7.1-fpm Commented Sep 13, 2019 at 14:48

1 Answer 1

12

The image php:7.1-fpm uses Debian Buster and, for some reasons that I'm unable to figure out at the moment, the php-xdebug appears to be not available in the repo even though the package appears in the site (https://packages.debian.org/buster/php-xdebug).

I rewrote the Dockerfile in a way that it works but I'll keep checking.

Dockerfile:

FROM php:7.1-fpm

RUN pecl install xdebug

RUN echo 'zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so' | tee /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_handler=dbgp" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port=9000" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=on" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back=0" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.idekey=docker" | tee -a /usr/local/etc/php/conf.d/xdebug.ini
Sign up to request clarification or add additional context in comments.

2 Comments

If it's not working, check the location of the xdebug.so file. It was no-debug-non-zts-20190902 for me.
Unfortunately pecl installation is deprecated in 2025, would be great to have modern answer...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.