Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MrZenW/d1ba99e7199a64a563b2d0726fd1c966 to your computer and use it in GitHub Desktop.
Save MrZenW/d1ba99e7199a64a563b2d0726fd1c966 to your computer and use it in GitHub Desktop.
How to configure PHP Xdebug with Docker and VSCode

How to Configure PHP Xdebug with Docker and VSCode

- File list -

  • Dockerfile
  • docker-compose.yml
  • mrzenw.nginx.conf
  • php.ini
  • xdebug.ini
  • .vscode/launch.json
version: "3"
# https://dev.to/_mertsimsek/using-xdebug-with-docker-2k8o
services:
php-fpm-dev:
build:
# context - the directory where the Dockerfile is
context: ./.
image: mrzenw--image-php
container_name: mrzenw--container--php-fpm
environment:
- MRZENW_ENV=DEV
volumes:
# app
- ./src:/var/www/app/src
- ./public_html:/var/www/app/public_html
# dev
- ./log:/var/www/app/log
# php
- ./php.ini:/usr/local/etc/php/php.ini
- ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
nginx:
image: nginx:latest
container_name: mrzenw--container--nginx
ports:
- "8888:80"
volumes:
- ./src:/var/www/app/src
- ./public_html:/var/www/app/public_html
- ./mrzenw.nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php-fpm-dev
FROM php:7.4-fpm-alpine
WORKDIR /var/www/app
RUN apk update \
&& apk add --no-cache libzip-dev git mysql-client curl libmcrypt libmcrypt-dev openssh-client icu-dev \
libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev g++ make autoconf \
&& docker-php-source extract \
&& pecl install xdebug redis \
&& docker-php-ext-enable xdebug redis \
&& docker-php-source delete \
&& docker-php-ext-install mysqli pdo_mysql soap intl zip \
# && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.idekey=mrzenw" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# && echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/*
CMD ["php-fpm", "-F"]
EXPOSE 9000
{
// !!! Place this file to the location: `.vscode/launch.json`
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
// "hostname": "127.0.0.1",
"port": 9003,
"pathMappings": {
"/var/www/app/public_html": "${workspaceFolder}/public_html",
"/var/www/app/src": "${workspaceFolder}/src",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}/html",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "dev-server.php",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
server {
listen 80;
server_name web;
root /var/www/app/public_html;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php-fpm-dev:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
[PHP]
engine = On
short_open_tag = On
precision = 14
output_buffering = Off
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 100
disable_functions = dl
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 30
max_input_time = 60
memory_limit = 256M
error_reporting = E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
error_log = /var/www/app/log/php_error.log
variables_order = "EGPCS"
request_order = "GP"
register_argc_argv = On
auto_globals_jit = On
post_max_size = 64M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
include_path = ".:/opt/php72/lib/php"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 64M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = On
default_socket_timeout
cli_server.color
date.timezone = Asia/Riyadh
pdo_mysql.cache_size = 2000
pdo_mysql.default_soc
sendmail_path = /usr/sbin/sendmail -t
mail.add_x_header
sql.safe_mode =
odbc.allow_persistent = Off
odbc.check_persistent = Off
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M"
mysqli.max_persistent = -1
mysqli.allow_persistent = Off
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect =
mysqlnd.collect_statistics = Off
mysqlnd.collect_memory_statistics =
pgsql.allow_persistent = Off
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice
bcmath.scale
session.save_handler = files
session.save_path = "/tmp"
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 100
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fields"
zend.assertions
tidy.clean_output =
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit
ldap.max_links
; [Xdebug]
; xdebug.start_with_request=1
; xdebug.remote_autostart=1
; xdebug.remote_enable=on
; xdebug.default_enable=1
; xdebug.remote_host=host.docker.internal
; xdebug.remote_port=9001
; xdebug.remote_connect_back=0
; xdebug.profiler_enable=0
; xdebug.remote_log="/tmp/xdebug.log"
; xdebug.profiler_output_dir="/var/www/html/profiler"
; xdebug.profiler_output_name="cachegrind.out.%p"
; xdebug.cli_color=1
; xdebug.profiler_append=1
; xdebug.remote_handler=dbgp
; xdebug.idekey=mrzenw
[Xdebug]
; https://dev.to/_mertsimsek/using-xdebug-with-docker-2k8o
; https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
; https://xdebug.org/docs/step_debug#starting
xdebug.mode=debug
xdebug.client_port=9003
xdebug.client_host=host.docker.internal
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.idekey=mrzenw
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.log=/var/www/app/log/xdebug.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment