在附加到Docker容器的VSCODE实例中设置XDEBUG
我想为WordPress建立一个开发环境,该环境支持通过Xdebug进行IDE调试,并包含在Docker容器中。
- 我正在使用WSL2 / Ubuntu 18.04工作,
- 我正在使用MySQL官方映像,
- 我正在使用WordPress映像构建在WordPress官方映像上, xdebug通过PECL安装< / strong>
- 我是 strong>从本地文件夹中复制php.ini和xdebug.ini的配置文件
- 使用 ms远程容器扩展名将VSCODE实例连接到容器上
- 在启动我的容器后,我将 Xdebug Team的官方PHP DEBUG VSCODE扩展是在VSCODE的附件实例中,
- 我会自动生成启动。JSON文件,用于php的JSON文件
- ,我设置了一个断点,并通过按下 f5 启动调试器
>是调试器开始,使我在我为Xdebug设置的端口(9003)设置的端口打开一个浏览器,但是页面未加载,未达到断点,并且VSCODE中的Debugger选项卡显示了几个错误,例如:<代码>失败初始化连接1:连接关闭(在关闭)
我尝试了其他略有不同的方法,例如从源使Dockerfile构建Xdebug以及来自Intern Internet的INI文件的其他设置,但是最终结果总是相同的。
如果我尝试通过浏览器运行xdebug_info()
,我将获得一个正常的输出,如果我尝试从控制台运行文件,我会得到此错误:
xdebug:[步骤调试]无法连接到调试客户端。尝试:host.docker.internal:9003(通过xdebug.client_host/xdebug.client_port): - (
与docker-compile输出相符的类似错误。
我尝试将9003端口转发给9003端口 行为没有
- compile
,但
version: "3.6"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
build:
context: ./wordpress
dockerfile: Dockerfile
volumes:
- wordpress_data:/var/www/html
ports:
- "8080:80"
# - "9003:9003"
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
改变
FROM wordpress:latest
RUN apt-get update && \
apt-get -y install git
# RUN git config --global url."https://github".insteadOf git://github
RUN pecl install xdebug
COPY ../config/ /
RUN docker-php-ext-enable xdebug
。 local/etc/php/php.ini (从php.ini开发中编辑)
...
[Xdebug]
xdebug.remote_autostart = 1
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.show_local_vars = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
(由于似乎没有跟踪这一点,所以我也尝试了从php.ini开发到php.ini的符号链接容器控制台,然后在此处添加变量。)
wordpress/config/usr/local/etc/php/php/conf.d/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.mode=develop,debug,trace,profile,coverage
xdebug.start_with_request = yes
xdebug.discover_client_host = 0
xdebug.remote_connect_back = 1
xdebug.client_port = 9003
xdebug.client_host='host.docker.internal'
xdebug.idekey=VSCODE
I want to set up a development environment for WordPress which supports IDE debugging through Xdebug and is contained in a docker container.
- I'm working from WSL2 / Ubuntu 18.04
- I'm using a MySQL official image
- I'm using a WordPress image built on top of the WordPress official image with Xdebug installed through PECL
- I'm copying configuration files for php.ini and xdebug.ini from a local folder
- After launching my container I'm attaching a VSCode instance to the container by using ms Remote Containers extensions
- I'm installing the official PHP debug VSCode extension from the Xdebug team in the attached instance of VSCode
- I'm automatically generating a launch.json file for PHP
- I'm setting a breakpoint and launching the debugger by pressing F5
What happens is that the debugger starts, offering me to open a browser at the port I set for Xdebug (9003), but the page doesn't load, the breakpoint isn't reached and the debugger tab in VSCode shows several errors such as: Failed initializing connection 1: connection closed (on close)
I tried other slightly different methods such as having the dockerfile build Xdebug from source as well as other setups for the ini files from tutorials found on the internet, but the end result is always the same.
If I try to run xdebug_info()
through the browser I get a normal output, if I try to run the file from console I get this error:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
which is in line with similar errors I get in the docker-compile output.
I tried forwarding the 9003 port with docker-compile, but the behavior didn't change.
These are my docker and config files:
docker-compose.yml
version: "3.6"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
build:
context: ./wordpress
dockerfile: Dockerfile
volumes:
- wordpress_data:/var/www/html
ports:
- "8080:80"
# - "9003:9003"
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
wordpress/Dockerfile
FROM wordpress:latest
RUN apt-get update && \
apt-get -y install git
# RUN git config --global url."https://github".insteadOf git://github
RUN pecl install xdebug
COPY ../config/ /
RUN docker-php-ext-enable xdebug
wordpress/config/usr/local/etc/php/php.ini (edited from php.ini-development)
...
[Xdebug]
xdebug.remote_autostart = 1
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.show_local_vars = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
(Since it seems this isn't being tracked I also tried making a symbolic link from php.ini-development to php.ini from the container console, then adding the variables there.)
wordpress/config/usr/local/etc/php/conf.d/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.mode=develop,debug,trace,profile,coverage
xdebug.start_with_request = yes
xdebug.discover_client_host = 0
xdebug.remote_connect_back = 1
xdebug.client_port = 9003
xdebug.client_host='host.docker.internal'
xdebug.idekey=VSCODE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论