Vscode uses Xdebug to debug thinkPHP

Vscode uses Xdebug to debug thinkPHP

  1. First determine the xdebug version to use, the official website provides an online query tool.
    https://xdebug.org/wizard
    Execute php -i on the installed host, and paste the input result into the text box on the website. Click the Analyze my phpinfoi() output button.
    As shown in the figure below, the installed version and download address will be prompted
    insert image description here

  2. After the download is complete, enter the folder and compile

cd xdebug-3.1.3

请将PHP替换成真实的路径

开始编译
/usr/local/opt/[email protected]/bin/phpize

./configure --enable-xdebug --with-php-config=/usr/local/opt/[email protected]/bin/php-config

make && make install

编译成功后 会输出 so的地址
  1. Modify the PHP configuration file php.ini, and the address of the configuration file can be viewed in phpinfo.
在配置文件末行添加以下代码
zend_extension=/usr/local/Cellar/[email protected]/7.4.28_1/pecl/20190902/xdebug.so
[xdebug]
xdebug.mode = debug 
xdebug.start_with_request = yes 
xdebug.client_port = 9003
xdebug.client_host= 127.0.0.1
xdebug.idekey=VSCODE

请注意Xdebug3版本和2版本的配置文件是不一样的,我这里是Xdebug3的示例
  1. Visual Studio Code installs the PHP Debug plug-in, just search and download it in the plug-in store.
  2. Configure lanuch.json
{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        }
    ]
}

这里的端口一定要和第3步的端口对应。
  1. Add a breakpoint to the code that needs to be debugged, click the Start Debugging button (or press F5)
    insert image description here

  2. When the browser opens the page to be debugged, it will automatically enter the breakpoint debugging.

insert image description here

  1. Then you can debug according to your actual needs.

Guess you like

Origin blog.csdn.net/lixu1119545729/article/details/123430965