调试php 7 Xdebug 2.4.0RC3 mac os时出现502错误的网关

Ale*_*lev 5 php homebrew xdebug nginx

我使用的最新版本PHP (7.0.2),并xdebug (2.4.0RC3)phpstorm 9.0.2当我开始调试我立即得到

error "502 Bad Gateway"
Run Code Online (Sandbox Code Playgroud)

有时我设法逐步执行几行代码,但是无论如何我还是得到了错误。

当我拥有的先前版本时PHP (5.6)xdebug一切都很棒。

PS php,nginx和xdebug与homebrew一起安装。

Mik*_*oot 4

你可以尝试这个:打开你的 php.ini,抱歉我不知道它在 MacOS 中的位置,在 Ubuntu 中它位于

/etc/php/7.0/fpm/php.ini
Run Code Online (Sandbox Code Playgroud)

使用您最喜欢的文本编辑器打开它,并具有保存配置文件所需的权限。转到 xdebug 部分并检查您是否已正确设置它。就我而言,它看起来像在下面。请注意,您的情况下 xdebug.so 的路径可能不同。

[Xdebug]
zend_extension="/usr/lib/php/20151012/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="\tmp"
xdebug.idekey="PHPSTORM"
xdebug.remote_autostart=1
xdebug.remote_host=192.168.10.10
xdebug.remote_mode=req
xdebug.remote_connect_back=1
xdebug.max_nesting_level=200
xdebug.var_display_max_depth=1000
xdebug.var_display_max_children=256
xdebug.var_display_max_data=4096

;this line below to prevent debug stop timeout
request_terminate_timeout=600s
Run Code Online (Sandbox Code Playgroud)

php.ini 中要检查的另一件事是

max_execution_time = 600
Run Code Online (Sandbox Code Playgroud)

我已将其设置为以秒为单位,如上所述,以防止停止调试会话,默认情况下将其设置为 30 秒

接下来您需要检查的是 nginx 配置,我已将这些行添加到主 nginx.conf http 部分

http {

    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    fastcgi_read_timeout 600s;
    proxy_read_timeout 600s;
    fastcgi_buffers 8 16k;
    fastcgi_send_timeout 600s;
    fastcgi_buffer_size 32k;

   #other standard settings below...
Run Code Online (Sandbox Code Playgroud)

我添加它们是为了给我更多的时间来调试会话,这样它就不会在 600 秒内停止。

全部编辑完毕后。重新启动 php7.0-fpm 和 nginx。我不确定它在 MacOS 中是如何完成的,在 Ubuntu 中是通过以下方式完成的:

 sudo service php7.0-fpm reload
 sudo service php7.0-fpm restart
 sudo service nginx reload
 sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)

也许重新加载然后重新启动有点矫枉过正,但要保险:)

另请查看 nginx 的 error.log 文件,在 Ubuntu 中,它们位于 /var/logs/nginx/ 中,有 error.yourdomain.log 转到最后几行,看看发生了什么。希望它会有所帮助。

UPD:对于任何将使用带有隧道的 Homestead 的人ngrok(或者例如ssh -R 3000:localhost:8000 user@yourserver.domain,然后在公共站点上,您将设置 nginx 作为端口 80 上某个域的反向代理,以从通过 SSH 隧道传输的 3000 进行读取),以将本地开发公开到互联网。

要启用调试,您需要注释掉该行xdebug.remote_connect_back=1或将其值设置为0。否则 xdebug 将获取X-Forwarded-For其他标头,并尝试连接回 nginx,但不会连接到本地开发,并且调试将不会启动。