【问题标题】:Why does assembly of Vagrant and Xdebug not works on latest versions of PHP?为什么 Vagrant 和 Xdebug 的程序集不适用于最新版本的 PHP?
【发布时间】:2021-04-03 22:14:25
【问题描述】:

我有 vagrant + nginx + PHP + xdebug 的工作程序集。 PHP 版本为 7.0 时一切正常,但当我将 PHP 升级到 7.2 或 7.4 时,Xdebug 停止工作。 Xdebug 安装了最新版本(3.0.1)。

Vagrantfile(部分):

sudo add-apt-repository -y ppa:ondrej/php
sudo add-apt-repository -y ppa:ondrej/nginx
sudo apt-get update

sudo apt-get install -y nginx
sudo apt-get install -y php7.0-fpm php7.0-xdebug

sudo service php7.0-fpm stop
sudo cp /vagrant/.provision/xdebug.ini /etc/php/7.0/mods-available/xdebug.ini
sudo service php7.0-fpm start

sudo service nginx start
sudo cp /vagrant/.provision/project.local /etc/nginx/sites-available/project.local
sudo chmod 644 /etc/nginx/sites-available/project.local
sudo ln -s /etc/nginx/sites-available/project.local /etc/nginx/sites-enabled/project.local
sudo service nginx restart

Nginx 配置:

server {

  listen 80;
  index index.php;
  server_name project.local www.project.local;

  root /var/www/project.local;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  location / {
    index index.php;
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }
}

Xdebug 配置:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.remote_host=192.168.33.11
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_cookie_expire_time = 36000
xdebug.remote_log=/var/www/project.local/.xdebug/xdebug.log
xdebug.idekey=vagrant

这些配置适用于 php7.0-fpm,但不适用于 php7.2-fpm 或 php7.4-fpm。问题出在哪里?

【问题讨论】:

    标签: php nginx vagrant xdebug


    【解决方案1】:

    Xdebug 安装了最新版本 (3.0.1)。

    您正在使用 Xdebug v3 但继续使用 Xdebug v2 配置参数。您需要通过Upgrading from Xdebug 2 to 3 Guide 并调整您的设置(主要是更改参数名称)。

    Xdebug v3 使用 不同 配置参数而不是 Xdebug v2。从我看到的十分之九的“xdebug”来看。您当前 php.ini 中的参数在 Xdebug v3 中执行 nothing(如果您检查 phpinfo() 输出的 Xdebug 部分,您会看到)。

    对于 Xdebug 3,它应该是这样的(基于您的原始配置):

    zend_extension=xdebug.so
    xdebug.mode = debug
    xdebug.start_with_request = yes
    xdebug.discover_client_host = true
    xdebug.client_host = 192.168.33.11
    xdebug.client_port = 9001
    xdebug.log = /var/www/project.local/.xdebug/xdebug.log
    xdebug.idekey = vagrant
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2019-12-21
      • 2019-06-29
      • 1970-01-01
      相关资源
      最近更新 更多