Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mac OS上的停靠PHP中使用XDebug 问题_Php_Shell_Docker_Xdebug - Fatal编程技术网

在mac OS上的停靠PHP中使用XDebug 问题

在mac OS上的停靠PHP中使用XDebug 问题,php,shell,docker,xdebug,Php,Shell,Docker,Xdebug,我无法从macOS上的停靠容器中使用Xdebug进行调试 我已经非常仔细地阅读了:,以及所有关于Stackoverflow和Github的建议解决方案。我还是被封锁了 在容器中 我可以连接到容器bash-c“clear&docker exec-it DockerizedSample sh” 它确认安装了XDebug # php -m -c [PHP Modules] Core ... xdebug ... [Zend Modules] Xdebug 它的配置似乎有效 # tail /usr/

我无法从macOS上的停靠容器中使用Xdebug进行调试

我已经非常仔细地阅读了:,以及所有关于Stackoverflow和Github的建议解决方案。我还是被封锁了

在容器中 我可以连接到容器
bash-c“clear&docker exec-it DockerizedSample sh”

它确认安装了XDebug

# php -m -c
[PHP Modules]
Core
...
xdebug
...

[Zend Modules]
Xdebug
它的配置似乎有效

# tail /usr/local/etc/php/conf.d/xdebug.ini

xdebug.idekey=PHPSTORM
xdebug.remote_host=172.17.0.1
xdebug.remote_enable=1
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
docker文件 如何重现这个问题
  • 下载
  • 转到PHPStorm文件夹并运行shell脚本
    /run.sh
  • 构建映像(可能需要几分钟)并运行容器后,应在其上打开浏览器

    我当前的测试环境
    • PhpStorm 2016.2.1
    • 建造#PS-162.1889.1,建造于2016年8月23日
    • 您拥有此版本的永久回退许可证
    • JRE:1.8.0_76-release-b216 x86_64
    • JVM:JetBrains s.r.o提供的OpenJDK 64位服务器虚拟机
    • 马科斯塞拉10.12(16A323)
    • 从官方版本1.12.1安装的mac Docker(内部版本:12133)2D5B4D9C3DAA089E3869E63555A47DD96DBF39856

    基本上,对于远程调试,扩展什么也不做,只是将cookie XDEBUG_会话设置为idekey的值。在你的“复杂”案例中,我最好先检查一下我脑海中出现的4件事:

  • 您的xdebug.remote_端口=9000
  • 如果php fpm在服务器端(使用IDE的那一侧)占用了端口#9000,则IDE无法开始侦听传入连接。Simply 9000是fpm的默认端口,这经常成为一个常见错误。这就是为什么我使用10000端口

  • docker run-e PHP\u IDE\u CONFIG=“serverName=Dockerized”
  • 这里的PHP_IDE_CONFIG不是一个。这实际上是nginx config指令的一个参数

  • 使用xdebug.remote\u log=/path/to/xdebug\u remote.log

  • 就我个人而言,我更喜欢使用旧软件。所以我在这里不是一个好帮手,但据我所知,Phpstorm现在使用不同的配置进行远程调试


  • 我终于找到了解决办法。它并不那么复杂。我使用“telnet”确定容器是否能够到达9000上的主机。事实并非如此。混乱来自远程主机IP。您必须使用您的本地主机IP

    HOST_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')
    
    docker run  -e PHP_IDE_CONFIG="serverName=DockerLocal"\
                    -e XDEBUG_CONFIG="idekey=PHPSTORM"\
                    -e XDEBUG_CONFIG="remote_host=$HOST_IP"\
                    -p 27017:27017 \
                    -p 8001:80\
                    -d --name DockerizedSample dockerizedsampleimage
    
    检查
    或者直接在

    上,自Docker 18.03发布以来,您的解决方案可以大大简化

    运行docker容器可以使用
    host.docker.internal
    DNS名称。这些DNS条目保存docker主机的IP地址

    所以不是
    xdebug.remote\u host=172.17.0.1
    你能行
    xdebug.remote\u host=host.docker.internal


    您还可以删除运行docker容器的运行脚本部分,该部分仅用于获取主机的IP地址。

    非常感谢Nikita。我已经找到了解决方案,它并不那么复杂。我将回答我自己的问题。这似乎是中所述的现在的
    host.docker.internal
    #!/bin/sh
    
    # Stop the container
    echo "Stop "
    docker stop DockerizedSample
    
    # Delete the container
    echo "Remove "
    docker rm DockerizedSample
    
    # Delete the image if necessary
    docker rmi dockerizedsampleimage:latest
    
    # Build the youdubserver image
    echo "Building with the current source"
    docker build -t dockerizedsampleimage:latest .
    
    # Run DockerizedSample container
    echo "Run container "
    
    # Run the container once.
    # then grab the IP of the HOST in the container
    # stop and relaunch with the good IP
    docker run  -d --name DockerizedSample dockerizedsampleimage
    HOST_IN_CONTAINER_IP=$(docker exec DockerizedSample /sbin/ip route|awk '/default/ { print $3 }')
    docker stop DockerizedSample
    docker rm DockerizedSample
    
    # Run the debuggable container
    docker run  -e PHP_IDE_CONFIG="serverName=Dockerized"\
                -e XDEBUG_CONFIG="remote_host=$HOST_IN_CONTAINER_IP"\
                -p 27017:27017 \
                -p 8001:80\
                -d --name DockerizedSample dockerizedsampleimage\
    
    # Start mongod
    echo "Start mongod "
    docker exec DockerizedSample service mongod start
    
    echo "IP in Docker Host"
    echo "$HOST_IN_CONTAINER_IP"
    
    echo "Local IP"
    ipconfig getifaddr en0
    
    # Open localhost in a browser on macOS
    if [[ "$OSTYPE" =~ ^darwin ]];
        then open http://localhost:8001/
    fi;
    
    HOST_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')
    
    docker run  -e PHP_IDE_CONFIG="serverName=DockerLocal"\
                    -e XDEBUG_CONFIG="idekey=PHPSTORM"\
                    -e XDEBUG_CONFIG="remote_host=$HOST_IP"\
                    -p 27017:27017 \
                    -p 8001:80\
                    -d --name DockerizedSample dockerizedsampleimage