xdebug - 如何在 PHP 7.2 和 PHP-FPM 上设置 Xdebug 分析

标签 xdebug fpm

我正在尝试在本地环境中使用 Xdebug 进行一些 PHP 分析。我运行的是 Ubuntu 22.04

我正在使用 PHP-FPM 通过虚拟主机运行 PHP v7.2。

php -v 输出

Zend Engine v4.1.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans

在/tmp/xdebug 上运行

sudo chown $USER:$USER /tmp/xdebug

在我的 /etc/php/7.2/fpm/php.ini/etc/php/8.1/apache2/php.ini 文件的底部我'我们把:

[xdebug]
zend_extension=xdebug
xdebug.output_dir = /tmp/xdebug
xdebug.remote_port=9001
xdebug.mode=develop,trace,profile

然后我就跑了

sudo systemctl restart apache2

启用的 Xdebug 功能显示在我的主/localhost/目录中的 phpinfo() 中(使用 PHP 8.*),但不在使用 PHP 7.2 的目录中显示

在我的虚拟主机 .conf 文件中,我将 PHP 版本设置为(我包含此版本是因为我不确定是否需要在此 .conf 文件中执行任何操作)

<FilesMatch \.php$>
        # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
        SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>

下图显示 phpinfo() 在 PHP 8.* 上获取我的 Xdebug 设置;使用 PHP 7.2 的目录显示未启用 Xdebug 设置。

XDEBUG FEATURES

我的疑问/问题:

  • 如何让 PHP 7.2 识别我的 Xdebug 设置?
  • 如何让 Xdebug 将配置文件输出到/tmp/xdebug? (我打算使用Webgrind)

最佳答案

I'm using PHP-FPM to run PHP v7.2

PHP 7.2 是 no longer supported ,因此请至少升级到 PHP 7.4,但最好是 PHP 8.0 或 8.1。

the directory using PHP 7.2 shows no Xdebug settings enabled.

  • 确保编辑正确的 php.ini 文件 - xdebug_info()phpinfo() 部分应显示哪些文件使用过。
  • 您是否也重新启动了 PHP 7.2 PHP-FPM? Apache 的 systemctl restart 行不会自动执行此操作。

sudo chown $USER:$USER /tmp/xdebug

这不太可能是正确的,因为它需要是可以写入该目录的 Apache 用户(通常是 www-data),而不是您的 shell 用户(这可能只是您的登录用户名 - 您可以使用 echo $USER 进行检查)。

关于xdebug - 如何在 PHP 7.2 和 PHP-FPM 上设置 Xdebug 分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73115456/

相关文章:

php - XDEBUG 适用于 URL,但不适用于 Cookie 设置

php - apache+php-fpm 的随机 403 错误

php - 如何将Xdebug 2.2.3(PHP 5.53)与PhpStorm 7.0集成

php - Vagrant、PhpStorm、HHVM 和 Xdebug

php - 更新后通过存储在 php-fpm 容器中的 nginx 提供新的静态文件

php - NGINX无法访问应用程序文件时的NGINX配置,以及php-fpm和docker

php - 在 ubuntu 上启动 php7.4-fpm 时出现问题

docker - 为什么访问我的本地网站时发生权限被拒绝?

php - 提高 Xdebug 性能

php - XDebug - 禁止将跟踪写入文件