Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem installing Xdebug in Docker and PhpStorm

Tags:

docker

xdebug

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
like image 899
Richard Nicson Avatar asked Sep 05 '26 01:09

Richard Nicson


1 Answers

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
like image 190
Stefano Avatar answered Sep 06 '26 19:09

Stefano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!