环境
- macOS
- PhpStorm 2020.1
- Homestead v13.2.1
- Laravel 7.30.6
PhpStorm 配置
打开 Preferences,首先配置 CLI Interpreter  新增一条,选择 From Docker, Vagrant…  然后选择 Vagrant 并设置 Vagrant Instance Folder 为你本地 Homestead 文件夹的地址,选择后出现 下面蓝色的 ssh://vagrant@… 即 ?  点击应用 Apply,OK  这样就设置好了。 
配置项目目录映射
- File/Directory 本地的地址
- Absolute path on the server 服务器的绝对地址(虚拟机目录)
 上面注意一下目录不要写错
配置 xdebug
进入虚拟机修改 php 配置文件,这里以 php7.4 为例:
vim /etc/php/7.4/fpm/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.idekey=PhpStorm
xdebug.max_nesting_level = 512
重启 fpm 使配置生效
/etc/init.d/php7.4-fpm restart
 Host 就是 Homestead.yaml 里 ip 的地址
单步调试
调试步骤:
- 主动开启 PhpStorm 对调试端口的监听
- 找到合适的代码位置打断点
- 访问对应的请求,并在请求地址后面添加 XDEBUG_SESSION_START 的参数
http://practice.com/api/user?XDEBUG_SESSION_START=PhpStorm
 最终效果  调试快捷键
- F7 通过当前行,进入下一行,如果该行是方法,则进入方法体
- F8 通过当前行,进入下一行,如果该行是方法,也直接进入下一行,不进入方法体
- F9 通过整个流程,全部顺序执行
参考
|