[PHP] XDebug+VS Code debugging PHP page

foreword

Recently uninstalled IDEA, because there is no activation code...
So I replaced Visual Studioand Xamarinused C#the development Androidapplication, but IDEAuninstalled, so naturally it can't be IDEAused to debug my PHPpage, so I have to Visual Studio Codeuse it to debug the PHP page I wrote.

Install the XDebug plugin

Get PHP version information

Different versions PHPcorrespond to different XDebugversions. If the version is wrong, I don’t know what will happen. Anyway, just download according to your own version!
Let’s PHPoutput phpinfo()the information now, check the two values ​​of sum Architectureand what I show here is sum , and record these two values ​​and your own version.Zend Extension Build
ArchitectureZend Extension Build
X64API320190902,TS,VC15PHP

Download the corresponding XDebug plugin

Download address: The plug-in download address
can be seen from the picture, x64corresponding to the download 64-bitversion, PHPthe version must be corresponding, and then Zend Extension Buildremember to see if there TSis a corresponding VCversion, and then we can download it.
Version Correspondence
WindowsThe system can be downloaded directly here dll, if it is, linuxplease download and compile it yourself.
XDebug for Linux

plugin installation

Under normal circumstances, the downloaded dllfiles will be placed in the corresponding PHPextension directory, that is, the PHPcorresponding extfolder.
Of course, you can leave it alone, because you must write the complete path when configuring the configuration XDebugof the module . Personally, I am more disciplined, so I put the files in the extension directory.zend_extension
dllPHP
PHP plugin directory

Profile settings

Once the plugin is in the folder, we need to configure the module settings php.iniof the file XDebug.
I will give my configuration below, but the complete XDebug configuration is far more than these parameters. If you need to modify other settings by yourself, you can Baidu.
Here, please pay attention to xdebug.remote_port=9000the statement of port number. This sentence corresponds to XDebugthe port number, so please be sure to remember your own custom port number. The port number I defined here is 9000.

;xdebug支持
[xdebug]
zend_extension ="安装PHP的根目录/ext/php_xdebug-2.9.2-7.4-vc15-x86_64.dll"

xdebug.remote_enable = On
xdebug.remote_autostart = On
;启用性能检测分析
xdebug.profiler_enable = On
;启用代码自动跟踪
xdebug.auto_trace=On
xdebug.profiler_enable_trigger = On
xdebug.profiler_output_name = cachegrind.out.%t.%p
;指定性能分析文件的存放目录
xdebug.profiler_output_dir ="安装PHP的根目录/tmp"
xdebug.show_local_vars=0

;配置端口和监听的域名
xdebug.remote_port= 9000
xdebug.remote_host="localhost"

Check whether the configuration takes effect

Restarting your own environment, LNMPor other environments, will not solve all problems just by restarting.
Then we print out phpinfo()the information again, if the relevant information appears, XDebugit means that the installation is successful, otherwise check XDebugwhether the installation is successful.
XDebug installed successfully

PHP Debug for VS Code

Follow the above steps to get it done, and then install VS Codethe PHP Debugplugin.
PHP Debug plugin
Then come to the debugging page and make corresponding launch.jsonsettings. Here, remember that the port number should correspond to XDebugthe port number in the above settings. My side is 9000, which corresponds to the above.

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
    
    
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

breakpoint debugging

At this point, write your own PHP page for testing. Remember to test the breakpoint under the root directory of the server web page, otherwise it will be useless.
If there is something wrong, please criticize and correct.

Guess you like

Origin blog.csdn.net/qq_19577209/article/details/108817477