文章目录
xdebug 扩展安装
不多做介绍,可以百度一下。
php -m |grep xdebug 检查xdebug是否安装
php --ri xdebug 检查xdebug配置项
本机php-fpm和phpStorm xdebug
虽然是本机xdebug调试,不过我用远程模式。
原理是: phpStorm监听本机9022端口, php-fpm通过127.0.0.1:9022连接到phpStormp实现调试。
配置phpStorm
phpStorm需要配置两项内容:
file mapping : 配置本地文件目录和服务器文件目录的位置
xdebug : phpStorm debug监听的端口
phpStorm xdebug监听端口9022
因为9000端口已被php-fpm占用,所以我们避开9000, phpStorm改为监听9022端口
phpStorm 文件mappings
因为是本机,所以file Directory和 absolute path one server目标配置为一样
配置php.ini
zend_extension="xdebug.so"
xdebug.remote_enable=On ; #远程调试
xdebug.remote_autostart=On ; #开启远程调试自动启动
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9022
测试可以正常debug:
http://127.0.0.1/index-api/v1/test
phpStorm 启动debug监听
Run -> Start Listening For PHP Debug Connections
本机docker php container和phpStorm xdebug
docker 镜像: youwen21/php-fpm72_redis_mysql_amqp_swoole:v1.4
其他配置和本机php-fpm连接phpStorm一样,只需要更改mapping, 因为docker 容器中代码目录不同
测试通过,可正常debug。