首页 > 解决方案 > 带有 docker 容器、反向代理中的 nginx 和 https 的 PhpStorm 调试器

问题描述

我需要一些帮助才能使用特定的开发配置来配置 PhpStorm 调试器。在我的电脑(192.168.1.23)上,我有一个 PHP 项目的源代码、一个 dbms 和一个 nginx 实例作为反向代理。配置 Nginx 是为了将所有流量发送到 docker 容器:

server {
        listen 80;
        listen [::]:80;

        server_name www.mysite.local;
        root /usr/share/nginx/html/;

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location / {
                index index.html  index.php;
        }

}

upstream backend  {
  # configuration in order to use apache inside docker container
  server 172.17.0.2:80;
}

docker 容器 (172.17.0.2) 已创建:

docker run -dP --add-host=db.local:172.17.0.1 \
      -e remote_connect_back_xdbg=1 \
      -e remote_host_xdbg='192.168.1.23' \
      -v /opt/live:/opt/live \
      --name local_php_apache_container local_php_apache_image

所以 Docker 将我的项目(位于 /opt/live)安装在容器的 /opt/live 内。该容器是带有 PHP 5.3 + Apache2 的 Debian 9。它会在电脑启动时使用以下命令自动启动:

docker exec -it local_php_apache_container /bin/bash

在 docker 容器内部,php.ini 中的 xdebug 配置为:

[xdebug]
xdebug.remote_connect_back=${remote_connect_back_xdbg}
xdebug.remote_enable=1
xdebug.remote_port=10123
xdebug.remote_handler=dbgp
xdebug.remote_log=/stackdriver/log/xdebug.log
xdebug.remote_mode=req
xdebug.remote_autostart=1
xdebug.remote_host=${remote_host_xdbg}
xdebug.idekey="netbeans-xdebug"

idkey 是 netbeans-xdebug,因为使用 netbeans,调试器可以正常工作(https://www.mysite.local/index.php?XDEBUG_SESSION_START=netbeans-xdebug,带有本地不受信任证书的 https)

在此处输入图像描述

在此处输入图像描述

但是我对 PHPStorm 和 PHP 解释器的位置有很多问题,包括 PHP 内置 Web 服务器和 PHP 远程调试配置......有什么建议吗?

标签: dockernginxhttpsphpstormxdebug

解决方案


推荐阅读