Docker php+mysql+xdebug
Steps to create configuration:
- Create docker-compose.yml
version: "2" services: web: image: nginx:latest ports: - "80:80" volumes: - ./apps/default:/apps/default - ./logs/nginx:/logs/nginx - ./config/nginx/xdebug:/etc/nginx/xdebug - ./config/nginx/hosts:/etc/nginx/hosts - ./config/nginx/init.conf:/etc/nginx/conf.d/default.conf php: build: dockerfile: Dockerfile context: ./ volumes: - ./apps/default:/apps/default - ./logs/xdebug:/logs/xdebug - ./config/php/custom.conf:/usr/local/etc/php-fpm.d/zz-custom.conf - ./config/php/xdebug.ini:/usr/local/etc/php/conf.d/zz-xdebug.ini - ./logs/php-fpm/:/tmp/xdebug_log
- Create apps/default/index.php file:
<?php $a=1; $b=2; $c=$a+$b; echo($c);
- Create configuration files:
----------------------- config/php/custom.conf: php_admin_flag[log_errors] = on php_flag[display_errors] = off ---------------------- config/php/xdebug.ini: ; Custom Xdebug config ; xdebug.remote_log="/logs/xdebug/remote.log" xdebug.remote_enable=1 xdebug.remote_autostart=0 xdebug.remote_connect_back=0 xdebug.remote_port=9000 ; xdebug.remote_host=DYNAMICALLY SET IN config/nginx/xdebug/remote.conf xdebug.profiler_enable_trigger=1 xdebug.profiler_enable=0 xdebug.profiler_output_dir="/logs/xdebug" xdebug.var_display_max_children=-1 xdebug.var_display_max_data=-1 xdebug.var_display_max_depth=-1 ----------------------- config/nginx/init.conf: include hosts/*.conf; -------------------------------- config/nginx/hosts/default.conf: server { listen 80; index index.php index.html; server_name localhost; error_log /logs/nginx/error.log; access_log /logs/nginx/access.log; root /apps/default; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include xdebug/remote.conf; } } -------------------------------- config/nginx/xdebug/remote.conf: set $xdebug_remote_host 'xdebug.remote_host=docker.for.mac.localhost'; if ($http_user_agent ~* 'windows') { set $xdebug_remote_host 'xdebug.remote_host=docker.for.win.localhost'; } fastcgi_param PHP_VALUE $xdebug_remote_host;
Use Netbeans to create new php project with sources from apps/default directory. Set breakpoint to any string within code and run project in debug mode.
Done.