xxxxxxxxxx
FROM php:7.4-apache
WORKDIR /app
RUN apt update
RUN apt install -y git libzip-dev zip && \
docker-php-ext-install zip mysqli pdo pdo_mysql && \
docker-php-ext-enable pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN a2enmod rewrite
RUN rm -rf /var/www/html && \
ln -s /app /var/www/html
RUN pecl install xdebug && docker-php-ext-enable xdebug
RUN echo "xdebug.mode=off" | tee -a /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini > /dev/null && \
echo "xdebug.start_with_request=yes" | tee -a /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini > /dev/null && \
echo "xdebug.client_host=host.docker.internal" | tee -a /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini > /dev/null
xxxxxxxxxx
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/app": "${workspaceRoot}"
},
"preLaunchTask": "enable:xdebug",
"postDebugTask": "disable:xdebug"
},
]
}
xxxxxxxxxx
This is my launch.json file for xdebug in vscode studio
you need to add absolute file file
path to mt project folder: "/Users/singh/local/offcina/html"
{
"configurations": [
{
"name": "Docker Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "/Users/singh/local/offcina/html",
},
}
]
}
this is my php.ini
[xdebug]
zend_extension = xdebug.so
xdebug.mode=${PHP_XDEBUG_MODE}
xdebug.start_with_request=yes
xdebug.client_host = ${PHP_XDEBUG_CLIENT_HOST}
xdebug.client_port=${PHP_XDEBUG_CLIENT_PORT}
xdebug.cli_color = ${PHP_XDEBUG_CLI_COLOR}
xdebug.idekey=VSCODE
xdebug.var_display_max_depth = ${PHP_XDEBUG_VAR_DISPLAY_MAX_DEPTH}
xdebug.max_nesting_level = ${PHP_XDEBUG_MAX_NESTING_LEVEL}
And this is my ENV under docker file
environment:
- "PHP_DISPLAY_ERRORS=Off"
- "PHP_XDEBUG_MODE=develop,debug"
- "PHP_XDEBUG_CLIENT_HOST=host.docker.internal"
- "PHP_XDEBUG_CLIENT_PORT=9003"
- "PHP_XDEBUG_CLI_COLOR=2"
- "PHP_XDEBUG_VAR_DISPLAY_MAX_DEPTH=20"
- "PHP_XDEBUG_MAX_NESTING_LEVEL=512"
- "PHP_IDE_CONFIG=serverName=docker-server"
xxxxxxxxxx
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "docker-compose exec exemplo sh -c 'sed -i \"/xdebug.mode=off/c\\xdebug.mode=debug\" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload'",
"label": "enable:xdebug"
},
{
"type": "shell",
"command": "docker-compose exec exemplo sh -c 'sed -i \"/xdebug.mode=debug/c\\xdebug.mode=off\" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload'",
"label": "disable:xdebug"
}
]
}