Good morning,
Thank you in advance for your time.
I am in a Docker environment with separation of PHP and Apache containers.
I’m using PHP8.2 and Symfony 7.1. I’m trying to add Xdebug in order to solve a SF code problem.
Anyway, despite the numerous tutorials followed, the VScode debugger does not react despite my breakpoints.
Here is my docker configuration:
dockerCompose
version: '3.9'
networks:
docker.network:
driver: bridge
services:
db:
image: mysql
container_name: mysql
restart: always
ports:
- "3306:8080"
networks:
- docker.network
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Yes
volumes:
- ./db/db_data:/var/lib/mysql
apache:
image: httpd
container_name: apache
ports:
- "80:80"
#- "443:443"
networks:
- docker.network
volumes:
- ../:/var/www
- ./apache/httpd-vhosts.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf
- ./apache/commun.conf:/usr/local/apache2/conf/extra/commun.conf
- ./apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
- ./hosts:/etc/hosts # Monter le fichier hosts
php82:
build: ./php/php8.2
container_name: php82
volumes:
- ../:/var/www
- ./php/php.ini:/etc/php/8.2/fpm/conf.d/30-custom.ini
- ./php/php.ini:/etc/php/8.2/cli/conf.d/30-custom.ini
- ./php/php.ini:/usr/local/etc/php/conf.d/30-custom.ini
- ./hosts:/etc/hosts # Monter le fichier hosts
environment:
- TZ=Europe/Paris
ports:
- "9000:9000"
- "9004:9004"
restart: always
networks:
- docker.network
extra_hosts:
- host.docker.internal:host-gateway
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin
ports:
- "86:80"
networks:
- docker.network
mailer:
image: mailhog/mailhog
container_name: mailer
ports:
- "1025:1025"
- "8025:8025"
networks:
- docker.network
DockerFile
# From
FROM phpdockerio/php:8.2-fpm
ARG DEBIAN_FRONTEND=noninteractive
# Run
RUN apt-get update
# Install Nano
RUN apt-get install -y nano
RUN apt-get install -y php8.2-mysqli
# Install necessary packages for pecl and ODBC
RUN apt-get update && apt-get install -y
php-pear
php8.2-dev
gcc
g++
make
autoconf
libc-dev
pkg-config
unixodbc-dev
libxml2-dev
php-xml
RUN apt-get install -y
libpng-dev
libjpeg-dev
libfreetype6-dev
libzip-dev
zip
&& pecl install gd
&& docker-php-ext-enable gd
&& pecl install mysqli
&& docker-php-ext-enable mysqli
&& pecl install pdo
&& docker-php-ext-enable pdo
&& pecl install pdo_mysql
&& docker-php-ext-enable pdo_mysql
&& pecl install zip
&& docker-php-ext-enable zip
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install SQL Server extensions
RUN pecl config-set php_ini /etc/php/8.2/fpm/php.ini
&& pecl install sqlsrv
&& pecl install pdo_sqlsrv
&& printf "; priority=20nextension=sqlsrv.son" > /etc/php/8.2/mods-available/sqlsrv.ini
&& printf "; priority=30nextension=pdo_sqlsrv.son" > /etc/php/8.2/mods-available/pdo_sqlsrv.ini
&& phpenmod -v 8.2 sqlsrv pdo_sqlsrv
# Install necessary packages for MS ODBC Driver
RUN apt-get update && apt-get install -y
curl
apt-transport-https
gnupg
# Add Microsoft's repo for the latest ODBC driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
# Install the MS ODBC driver for SQL Server
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y
msodbcsql17
mssql-tools
# Ensure the PHP configuration directory exists
RUN mkdir -p /usr/local/etc/php/conf.d
# Install Xdebug
RUN pecl install xdebug
# Configure Xdebug
RUN echo "zend_extension=$(find /usr/lib/php/ -name xdebug.so)" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.log=/var/log/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Créer le répertoire de travail
RUN mkdir -p /var/www
# Automatiser les permissions du répertoire
RUN chown -R www-data:www-data /var/www
&& chmod -R 755 /var/www
30-custom.ini
display_errors = On
display_startup_errors = On
log_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
directorypermissions = "0775"
date.timezone = Europe/Paris
max_execution_time = 500
max_input_time = 500
memory_limit = 256M
; zend_extension=/usr/lib/php/20220829/xdebug.so
; xdebug.mode=debug
; xdebug.start_with_request=yes
; xdebug.client_host=172.0.0.1
; xdebug.client_port=9004
zend_extension=/usr/lib/php/20220829/xdebug.so
; ; zend_extension=xdebug.so
xdebug.mode=debug
xdebug.idekey=XDEBUG_SESSION_START
xdebug.start_with_request=yes
xdebug.log=/dev/stdout
xdebug.log_level=0
xdebug.client_port=9000
xdebug.client_host=host.docker.internal
xdebug.discover_client_host=true
xdebug.remote_host=host.docker.internal
I did a php_info() where I have the instantiation of Xdebug
enter image description here
I then configured my VSCode with the php debug extension, and the debugger settings. Here is my lunch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000,
"hostname": "127.0.0.1",
"pathMappings": {
"/var/www": "${workspaceFolder}"
}
}
]
}
I tested either with POSTMAN or by directly calling the url http://datalookup.local/index.php/lookup/liste-marques
For browsers, I added the debbug helper extension, which is activated. Unfortunately, absolutely nothing happens in VSCode.
I tested with another port 9004, which I opened on the docker container, but nothing.
I don’t really know where to turn anymore. Can you help me?
Do you need additional information?
I tested with different ports, I tested with different keys, and changing networks.
I followed various tutorials including that of grafikart.
text
text
Gael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.