安装 PHP 并配置设置后 Xdebug 不工作
Xdebug not working after I install PHP and configure settings
我使用 pecl install xdebug
在 PHP 7.3 上安装了 Xdebug
当我将这些设置添加到 /etc/php/7.3/apache2/php.ini
并重新加载 Apache 时,页面失败并显示没有数据发送到服务器。
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE
xdebug.scream=1
不确定为什么它不起作用。
(In the original version of your question, your configuration was commented out, now you've edited that bit out, leaving the next couple of paragraphs kinda out of the loop)
似乎 php 会很乐意将这些行视为配置文件中的注释。解释器忽略散列之后的所有内容。
所以那些配置行是完全无效的。
要验证是否正在加载您的配置,请创建一个像这样的简单文件:
<php
phpinfo();
加载此文件将告诉您有关 PHP 配置的所有信息。如果 Xdebug 已成功加载,您将看到如下内容:
并在加载的配置设置下方:
这些是最重要的设置,实际加载并启用 Xdebug 扩展:
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
重要:您需要检查 /usr/lib/php/20180731/xdebug.so
是否确实存在,如果不存在,请找到您的 xdebug 模块的实际位置。
下一行假定网络服务器和浏览器安装在同一台机器上的同一 IP 上,这对于简单设置可能是正确的:
xdebug.remote_host=127.0.0.1
作为替代方案,您可以告诉 Xdebug 连接回发出原始请求的 IP
xdebug.remote_connect_back=On
通过以下行,您可以了解 IDE 正在侦听的端口。它默认是 9000,所以你通常不需要设置它,除非你需要监听一个非标准端口(例如,同时调试多个项目,针对不同的解释器)。但通常情况下,您可以安全地省略这一行:
xdebug.remote_port=9000
模块加载并启用后,您还可以使用环境变量配置一些 Xdebug 设置。具体来说 xdebug.remote_host
、xdebug.remote_port
、xdebug.remote_mode
和 xdebug.remote_handler
例如:
export XDEBUG_CONFIG="remote_host=192.168.0.3 remote_port=9005"
- xdebug 与 php7.3 版本 < 2.7
不兼容
- 您可以安装与 php7.3 兼容的 xdebug beta 版本:
pecl install xdebug-beta
https://bugs.xdebug.org/view.php?id=1584
更新:
XDEBUG 发布了新版本,并且有不同的配置。新版本兼容PHP>=7.4。看看:
要在 php7.3 运行 上安装 xdebug,请执行以下命令:
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3
现在下载源代码并通过运行以下命令安装:
cd /tmp
wget http://xdebug.org/files/xdebug-2.8.0.tgz
tar -xzvf xdebug-2.8.0.tgz
cd xdebug-2.8.0
phpize
./configure
sudo make
sudo make install
我使用 pecl install xdebug
当我将这些设置添加到 /etc/php/7.3/apache2/php.ini
并重新加载 Apache 时,页面失败并显示没有数据发送到服务器。
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE
xdebug.scream=1
不确定为什么它不起作用。
(In the original version of your question, your configuration was commented out, now you've edited that bit out, leaving the next couple of paragraphs kinda out of the loop)
似乎 php 会很乐意将这些行视为配置文件中的注释。解释器忽略散列之后的所有内容。
所以那些配置行是完全无效的。
要验证是否正在加载您的配置,请创建一个像这样的简单文件:
<php
phpinfo();
加载此文件将告诉您有关 PHP 配置的所有信息。如果 Xdebug 已成功加载,您将看到如下内容:
并在加载的配置设置下方:
这些是最重要的设置,实际加载并启用 Xdebug 扩展:
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
重要:您需要检查 /usr/lib/php/20180731/xdebug.so
是否确实存在,如果不存在,请找到您的 xdebug 模块的实际位置。
下一行假定网络服务器和浏览器安装在同一台机器上的同一 IP 上,这对于简单设置可能是正确的:
xdebug.remote_host=127.0.0.1
作为替代方案,您可以告诉 Xdebug 连接回发出原始请求的 IP
xdebug.remote_connect_back=On
通过以下行,您可以了解 IDE 正在侦听的端口。它默认是 9000,所以你通常不需要设置它,除非你需要监听一个非标准端口(例如,同时调试多个项目,针对不同的解释器)。但通常情况下,您可以安全地省略这一行:
xdebug.remote_port=9000
模块加载并启用后,您还可以使用环境变量配置一些 Xdebug 设置。具体来说 xdebug.remote_host
、xdebug.remote_port
、xdebug.remote_mode
和 xdebug.remote_handler
例如:
export XDEBUG_CONFIG="remote_host=192.168.0.3 remote_port=9005"
- xdebug 与 php7.3 版本 < 2.7 不兼容
- 您可以安装与 php7.3 兼容的 xdebug beta 版本:
pecl install xdebug-beta
https://bugs.xdebug.org/view.php?id=1584
更新:
XDEBUG 发布了新版本,并且有不同的配置。新版本兼容PHP>=7.4。看看:
要在 php7.3 运行 上安装 xdebug,请执行以下命令:
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3
现在下载源代码并通过运行以下命令安装:
cd /tmp
wget http://xdebug.org/files/xdebug-2.8.0.tgz
tar -xzvf xdebug-2.8.0.tgz
cd xdebug-2.8.0
phpize
./configure
sudo make
sudo make install