【环境搭建】vscode调试php

发布时间 2023-04-02 19:25:22作者: Mr_Soap

待解决问题

使用vscode和phpstudy实现PHP的本地调试

解决办法

1.打开xdebug

找到网站使用的PHP版本,在设置中将Xdebug调试组件打开,并确认端口是9000

找到php扩展目录下的php_xdebug.dll,例如我电脑上的路径是"D:\software\phpstudy_pro\Extensions\php\php7.3.4nts\ext\php_xdebug.dll"
打开php.ini,在末尾添加以下内容

[Xdebug]
zend_extension=D:/software/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=Off
xdebug.trace_output_dir=D:/software/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.trace
xdebug.profiler_enable=Off
xdebug.profiler_output_dir=D:/software/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.profiler
xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1

要确保路径与上面找到的路径一致
完成以上操作后通过phpinfo()查看信息,若出现以下信息即打开xdebug成功

2.配置PHP Debug

在vscode中安装扩展PHP Debug,在此扩展的settings.json末尾添加以下两行

"php.validate.executablePath":"D:/software/phpstudy_pro/Extensions/php/php7.3.4nts/php.exe",
"php.debug.executablePath": "D:/software/phpstudy_pro/Extensions/php/php7.3.4nts/php.exe"

接下来在运行和调试中点击创建launch.json文件并将所有端口改为上面的9000

保存后重启Apache即可