具有天才还不够,你们一定要能够善于运用它。——罗休共柯

之前写过phpstorm配置php项目debug

但是今天踩坑了,由于我使用了多种方式安装php

例如

phpenv安装php8.x

php集成环境servbay

以及我mac上已存在的php环境(忘了当时咋装的)

这里今天我刚好用的是php8.x,我们首先查看版本:

1
2
3
4
5
6
Github-Id-VampireAchao:cardcardcommunition achao$ php --version
PHP 8.3.5 (cli) (built: May 20 2024 16:56:06) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.5, Copyright (c) Zend Technologies
with Zend OPcache v8.3.5, Copyright (c), by Zend Technologies
with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

注意这里写的是Xdebug v3.3.1,那么注意需要按照官方文档Xdebug 3的方式配置

我们查看配置文件

1
2
3
4
5
Github-Id-VampireAchao:cardcardcommunition achao$ php --ini
Configuration File (php.ini) Path: /Users/achao/.phpenv/versions/8.3.5/etc
Loaded Configuration File: /Users/achao/.phpenv/versions/8.3.5/etc/php.ini
Scan for additional .ini files in: /Users/achao/.phpenv/versions/8.3.5/etc/conf.d
Additional .ini files parsed: /Users/achao/.phpenv/versions/8.3.5/etc/conf.d/xdebug.ini

修改/Users/achao/.phpenv/versions/8.3.5/etc/conf.d/xdebug.ini,修改完后

1
2
3
4
5
6
7
8
Github-Id-VampireAchao:cardcardcommunition achao$ cat /Users/achao/.phpenv/versions/8.3.5/etc/conf.d/xdebug.ini
#zend_extension="/Users/achao/.phpenv/versions/8.3.5/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so"
#html_errors=on
[xdebug]
zend_extension="/Users/achao/.phpenv/versions/8.3.5/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so"
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port="9003"

然后细节来了,在phpstorm里的settings(设置)里找到PHP

然后找到CLI Interpreter这一栏,这里需要确保配置的是刚我们环境变量里的配置,查看一下环境变量对应命令所在位置

1
2
Github-Id-VampireAchao:cardcardcommunition achao$ whereis php
php: /Users/achao/.phpenv/shims/php

如果没有的话,点右边三个点...配置一下,大概目录都配置好就行

这三个目录分别用下面的命令可以找到

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Github-Id-VampireAchao:cardcardcommunition achao$ whereis php
php: /Users/achao/.phpenv/shims/php
Github-Id-VampireAchao:cardcardcommunition achao$ php --ini
Configuration File (php.ini) Path: /Users/achao/.phpenv/versions/8.3.5/etc
Loaded Configuration File: /Users/achao/.phpenv/versions/8.3.5/etc/php.ini
Scan for additional .ini files in: /Users/achao/.phpenv/versions/8.3.5/etc/conf.d
Additional .ini files parsed: /Users/achao/.phpenv/versions/8.3.5/etc/conf.d/xdebug.ini

Github-Id-VampireAchao:cardcardcommunition achao$ find /Users/achao/.phpenv/versions/8.3.5/ -name "xdebug.so"
/Users/achao/.phpenv/versions/8.3.5//lib/php/extensions/no-debug-non-zts-20230831/xdebug.so
Github-Id-VampireAchao:cardcardcommunition achao$ find /Users/achao/.phpenv/ -name "xdebug.so"
/Users/achao/.phpenv//versions/8.3.5/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so
/Users/achao/.phpenv//versions/8.3.7/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so
Github-Id-VampireAchao:cardcardcommunition achao$