How to install xDebug on an php:alpine docker image?

0

I am trying to install xDebug on a PHP Alpine Linux Docker image, and although xDebug is successfully installed for the CLI, phpinfo() on the web doesn’t report the extension loaded. I’m on Linux. How can I solve this?

Here is the code:

Dockerfile:

FROM php:alpine

RUN apk update && apk upgrade

RUN apk add php-pear

RUN apk add php-openssl

RUN apk add bash

RUN \
    apk add --no-cache \
    apache2-proxy \
    apache2-ssl \
    apache2-utils \
    curl \
    git \
    logrotate \
    openssl

RUN apk add php$phpverx-apache2

RUN apk add openssl php-bcmath php-curl php-json php-mbstring php-pdo php-tokenizer php-xml php-zip

RUN apk add php-session

RUN apk add openrc --no-cache

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

COPY php.ini /var/www/localhost/htdocs/php.ini

COPY php.ini /etc/php81/php.ini

EXPOSE 80

CMD php artisan config:cache

RUN apk add --no-cache linux-headers \
    && apk add --update --no-cache --virtual .build-dependencies $PHPIZE_DEPS\
    && pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && pecl clear-cache \
    && apk del .build-dependencies

    COPY ./docker/php/conf.d/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

COPY ./apa.conf/apache.conf /etc/apache2/sites-available/000-default.conf

docker-compose.yml

version: "3"
services:
  php-apache-environment:
    container_name: php-apache-solon
    build: .
    volumes:
      - .:/var/www/localhost/htdocs/
      - ./apa.conf/apache.conf:/etc/apache2/sites-available/000-default.conf
      - ./docker/php/conf.d/xdebug.ini:/etc/php81/conf.d/docker-php-ext-xdebug.ini
      - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    ports:
      - 80:80
      - ${HOST_HTTPS_PORT}:443
    environment:
      XDEBUG_MODE: debug
      XDEBUG_CONFIG: client_host=172.17.0.1 client_port=9003
  db:
    image: mysql
    container_name: mysql-solon
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - /mysql-data:/var/lib/mysql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 7070:80
    restart: always
    environment:
      PMA_HOST: db
    depends_on:
      - db
  redis:
      image: redis:alpine
      container_name: myapp-redis
      command: redis-server --appendonly yes
      volumes:
      - ./data/redis:/data
      ports:
        - "8002:6379"
networks:
  internal:
    driver: bridge

xdebug.ini

zend_extension=xdebug.so

[xdebug]
xdebug.mode=develop,coverage,debug,profile
xdebug.idekey="vsc"
xdebug.start_with_request=yes
xdebug.log=/dev/stdout
xdebug.client_port=9003
xdebug.client_host=172.17.0.1

error_reporting.ini

error_reporting=E_ALL

apache.conf

Listen 443

LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so


<VirtualHost *:80>
       DocumentRoot "/var/www/html/public"
       ServerName 127.0.0.2

       <Directory "/var/www/html/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
</Directory>

</VirtualHost>