[英]How to debug docker container with PhpStorm
Can't debug the web app with the following configuration:无法使用以下配置调试 Web 应用程序:
Dockerfile: Dockerfile:
FROM php:7-fpm
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_host=site.dev" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_log=/var/www/site/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini
WORKDIR /var/www/site
nginx server (site.conf): nginx 服务器(site.conf):
server {
server_name site.dev www.site.dev;
root /var/www/site/src/UI/Web/Silex/Public;
...
}
docker-compose.yml: docker-compose.yml:
version: '2'
services:
php:
container_name: acme_php
build: etc/docker/development/php
volumes:
- ./:/var/www/site
nginx:
container_name: acme_nginx
build: etc/docker/development/nginx
ports:
- "80:80"
volumes:
- ./:/var/www/site
- ./etc/docker/development/nginx/site.conf:/etc/nginx/conf.d/site.conf
links:
- php
Running the server:运行服务器:
docker-compose up -d --build
Server:服务器:
Debug:调试:
Run/Debug configurations:运行/调试配置:
Pressing bug button opens chrome but doesn't stop in the breakpoint:按下 bug 按钮会打开 chrome 但不会在断点处停止:
Running phpinfo() looks like (xdebug area):运行 phpinfo() 看起来像(xdebug 区域):
xdebug.log: xdebug.log:
I: Connecting to configured address/port: site.dev:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/site/src/UI/Web/Silex/Public/index.php" language="PHP" xdebug:language_version="7.1.5" protocol_version="1.0" appid="6" idekey="18032"><engine version="2.5.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///var/www/site/src/UI/Web/Silex/Public/index.php" lineno="5"></xdebug:message></response>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Why it is not stopping in the breakpoint?为什么它不在断点处停止? :(
:(
Changes to make it work:更改以使其工作:
Dockerfile: Dockerfile:
FROM php:7-fpm
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/xdebug.ini \
WORKDIR /var/www/site
docker-compose.yml: docker-compose.yml:
version: '2'
services:
php:
container_name: acme_php
build: etc/docker/development/php
volumes:
- ./:/var/www/site
links:
- db
environment:
XDEBUG_CONFIG: "remote_host=192.168.1.99"
PHP_IDE_CONFIG: "serverName=site.dev"
nginx:
container_name: acme_nginx
build: etc/docker/development/nginx
ports:
- "80:80"
volumes:
- ./:/var/www/site
- ./etc/docker/development/nginx/site.conf:/etc/nginx/conf.d/site.conf
links:
- php
/etc/hosts (host machine): /etc/hosts(主机):
127.0.0.1 site.dev
Thanks for all the help in your comments @LazyOne感谢您在评论中提供的所有帮助@LazyOne
I had the same problem , my config:我有同样的问题,我的配置:
add this Dockerfile: :添加这个 Dockerfile: :
echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini &&
Info:信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.