适用平台:linux
发行版本:debian10
1.vscode下的php,debug环境搭建:
php环境搭建:php在vscode环境搭建见20.6.19另一篇博文
debug环境:在vscode下载插件PHP Debug或PHP Extension Pack(包含debug)
其他有用的插件:
2.下载依赖关系管理工具composer
通过百度composer中文网,下载中文镜像文件
安装方法见:https://pkg.phpcomposer.com/#how-to-install-composer
下面是通过官网推荐的修改 composer 的全局配置文件方法下载
composer config -g repo.packagist composer https://packagist.phpcomposer.com
3.安装后可以通过
composer -v --version
命令查看版本信息,确定是否安装成功
4.进入你的项目目录(这里我以我为例,项目位于我的nginx服务器配置文件的根目录下)
cd /home/Sun/
5.部署laravel项目(在第4步的目录下)
composer create-project laravel/laravel FirstProj
FirstProj表示项目的目录名
6.把项目在vscode中打开,即open floder,选择/home/Sun/FirstProj
7.为项目创建debug:
在vscode中点击debug图标,选择create a launch.json file,选择PHP环境
我的launch.json文件内容如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: 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
}
]
}
8.打开网址测试:localhost/FirstProj/server.php
9.遇到的一些问题,composer create-project命令创建项目失败:
错误提示形如:
- phpunit/phpunit 8.5.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.
说明php相关模块未下载,使用
sudo apt install php7.4-xxx
(xxx为模块名,如例子中dom,替换到xxx位置)
10.删除原来的项目,然后再次部署项目(见5.)
10.注意事项:
当使用sudo命令来部署项目(见5.)时,会出现问题,在实际过程中会遇到Vscode中无法为Laravel项目创建Debug文件,因为权限不够。