首页 > 解决方案 > 用 Xdebug 连接 nginx

问题描述

我想为我的 web 项目使用 Xdebug 我做配置,当我运行它时

php -S localhost:88 ./index.php

一切正常,Xdebug 工作并在断点处停止
但是当我想用 nginx 加载页面时,我遇到了问题
页面加载和我的断点不会停止页面的加载
我把我的配置放在这里
launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9004,
            "stopOnEntry":true,
            "log": true
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9004
        }
    ]
}

nginx

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

        root /home/azibom/Desktop/cyphy/cypht-master/site;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name localhost;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location ~ /\.ht {
            deny all;
        }
}

php.ini

[xdebug]
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9004

当我运行这个脚本时

<?php

xdebug_info();

我在浏览器中收到 500 错误

标签: phpnginxxdebug

解决方案


推荐阅读