[英]Using Xdebug and PhpStorm with Docker container on Windows
我正在嘗試使用 PhpStorm 使 Xdebug 為 Windows 上的 Docker 容器工作。 我閱讀了不同的文章和其他主題,但仍然無法正常工作。
在 docker-compose.yaml 內部,我的應用程序容器具有以下配置:
version: "3.7"
services:
#PHP Service
app:
build:
args:
user: user
uid: 1000
context: ./
dockerfile: docker/php/Dockerfile
image: rpg
container_name: rpg-app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
PHP_IDE_CONFIG: serverName=RpgServer
working_dir: /var/www
command: /var/www/docker/php/application-init.sh
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- rpg-app-network
depends_on:
- db
...
#Nginx Service
nginx:
image: nginx:1.17-alpine
container_name: rpg-nginx
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- rpg-app-network
depends_on:
- app
我有以下 PhpStorm 配置:
我使用 Chrome 的 Xdebug Helper 插件發送 session 密鑰
在phpinfo()
我可以看到 PHP 收到 Xdebug session 密鑰:
我正在 PhpStorm 中監聽 Xdebug 連接(在整個代碼中都有斷點):
我在啟用了 Xdebug Helper 的瀏覽器中運行應用程序。
然而。 斷點沒有阻塞,也沒有對 PhpStorm 的回調。
感謝LazyOne的幫助,我再次查看了配置,發現 Step Debugger 已禁用。
我在我的 php-fpm Dockerfile 中以以下方式安裝 Xdebug:
# Install xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
這是我原來的 Xdebug 配置:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
我添加了
xdebug.mode = debug
重新運行docker-compose up
我開始在容器日志中收到通知:
rpg-app | NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
我發現這個線程Xdebug: [Step Debug] 無法連接到調試客戶端
並補充說:
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
得到:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
現在一切正常::)
編輯:根據 LazyOne 的評論,我更新到 Xdebug v3 配置設置。 結果是:
[xdebug]
xdebug.idekey=PHPSTORM
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
xdebug.log=/var/www/storage/logs/xdebug.logs
從外觀上看,除了源路徑映射(您可以在 PHPStorm 的服務器下找到它)之外,您已經正確設置了所有內容。 這通常是斷點不起作用的原因。 還嘗試啟用“在第一行中斷”選項。
除非您真的需要 docker 組合來運輸,否則我強烈建議您使用Lando 。 它始終具有正確的 XDebug 配置,並且具有可使用的真實 (https) URL 有很大幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.