VScode的PHP远程调试模式Xdebug

目录

第一步、安装VScode中相应插件

remote-ssh的原理

ssh插件:

PHP相关插件:

第二步、安装对应PHP版本的xdebug

查看PHP具体配置信息的phpinfo页面

1、首先,打开php编辑器,新建一个php文件,例如:index.php

2、在index.php中,输入代码:phpinfo();

3、浏览器运行index.php页面,此时打印出了该php服务器上各个配置信息、组件信息的phpinfo页面。

​​​​​​​ 点击最下面的按钮

第三步、修改launch.json文件

第四步、修改php.ini文件

php.ini文件路径:

第五步、设置断点,开始调试

在test文件夹中新建一个index.php文件,配置如下


需要的配置环境:

VScode PHP

官方文档:使用 SSH 和 Visual Studio 代码在远程计算机上进行开发

第一步、安装VScode中相应插件

remote-ssh的原理

在Visual Studio代码远程- SSH扩展允许你打开任何远程计算机,虚拟机或容器上的远程文件夹与正在运行的SSH服务器,并充分利用VS代码的功能集。一旦连接到服务器,您就可以与远程文件系统上任何位置的文件和文件夹进行交互。

由于扩展直接在远程计算机上运行命令和其他扩展,因此无需在本地计算机上使用源代码即可获得这些好处。

ssh插件:

PHP相关插件:

如果你之前安装过PHP相关软件,在远程连接后会提示你该插件在此扩展在此工作区中被禁用,因为其被定义为在远程扩展主机中运行。请在'SSH:xxx.xxx.xxx.xxx'中安装扩展以进行启用。

因此,我们需要在当前环境下再次安装所需插件

第二步、安装对应PHP版本的xdebug

查看PHP具体配置信息的phpinfo页面

1、首先,打开php编辑器,新建一个php文件,例如:index.php
2、在index.php中,输入代码:phpinfo();
3、浏览器运行index.php页面,此时打印出了该php服务器上各个配置信息、组件信息的phpinfo页面。

在xdebug官网,将自己phpinfo的源代码复制进去

xdebug官网:Xdebug: Support --- Tailored Installation Instructions

点击最下面的按钮

第三步、修改launch.json文件

可以先打开一个文件,之后点击运行和调试,在点击设置按钮就会转到launch.json文件

加上如下配置

注意修改端口号

{

// 使用 IntelliSense 了解相关属性。

// 悬停以查看现有属性的描述。

// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "Listen for Xdebug",

"type": "php",

"request": "launch",

"port": 9001

},

{

"name": "Launch currently open script",

"type": "php",

"request": "launch",

"program": "${file}",

"cwd": "${fileDirname}",

"port": 0,

"runtimeArgs": [

"-dxdebug.start_with_request=yes"

],

"env": {

"XDEBUG_MODE": "debug,develop",

"XDEBUG_CONFIG": "client_port=${port}"

}

},

{

"name": "Launch Built-in web server",

"type": "php",

"request": "launch",

"runtimeArgs": [

"-dxdebug.mode=debug",

"-dxdebug.start_with_request=yes",

"-S",

"localhost:0"

],

"program": "",

"cwd": "${workspaceRoot}",

"port": 9001,

"serverReadyAction": {

"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",

"uriFormat": "http://localhost:%s",

"action": "openExternally"

}

}

]

}

第四步、修改php.ini文件

php.ini文件路径:

以本人为例:

本人将php安装在D:\software\computing\NSP\phpstudy路径下

php.ini文件夹则在D:\software\computing\NSP\phpstudy\phpstudy_pro\Extensions\php\php7.3.4nts路径下

注意:你要寻找对于php版本的phpx.x.xnts文件夹

第五步、设置断点,开始调试

在test文件夹中新建一个index.php文件,配置如下

在php中打开Apache

再次刷新即可

相关推荐
小Lu的开源日常34 分钟前
在 macOS 上设置 SSH 和 Git
git·macos·ssh
wkj0011 小时前
php7.4使用 new DateTime;报错 Class DateTime not found
php
tao3556672 小时前
树莓派免密登录(vs code/cursor)
linux·嵌入式硬件·ssh
杨浦老苏2 小时前
IntelliSSH:AI驱动的远程服务器管理软件
人工智能·docker·ai·ssh·群晖
等不到来世3 小时前
vscode设置默认终端terminal为git bash
vscode·terminal
亿坊电商4 小时前
VUE混合开发,选哪个PHP框架最顺手?
前端·vue.js·php
qinyia5 小时前
利用Wisdom SSH高效搭建CI/CD工作流
运维·ci/cd·ssh
Skrrapper8 小时前
【编程史】IDE 是谁发明的?从 punch cards 到 VS Code
c++·ide·vscode
量子联盟18 小时前
原创-基于 PHP 和 MySQL 的证书管理系统,免费开源
开发语言·mysql·php
mmsx1 天前
使用git生成ssh的ed25519密钥
运维·git·ssh