首先确保已经安装了 PHP 和 Visual Studio Code。
- 安装 PHP Extension Pack 插件:在 Visual Studio Code 中按
Ctrl/Cmd+Shift+X
打开扩展面板,搜索 PHP Extension Pack
并安装。
- 配置 PHP 路径:在 Visual Studio Code 中打开设置(
Ctrl/Cmd + ,
),搜索 php.validate.executablePath
,在输入框中输入 PHP 的绝对路径即可。
- 安装并配置 Xdebug 扩展:在 Visual Studio Code 中打开扩展面板,搜索
Xdebug
并安装。然后在设置中搜索 xdebug
,设置 xdebug.remote_enable
为 true
。
至此,你已经成功配置了 PHP 开发环境,在 VS Code 中编写 PHP 代码就能自动检查语法错误,并且可以使用 Xdebug 进行调试了。