Ubuntu下使用 PhpStorm 调试 PHP 的完整步骤
一 环境准备与安装
sudo apt-get update && sudo apt-get install php-xdebugsudo systemctl restart apache2sudo systemctl restart php{version}-fpm && sudo systemctl restart nginxphp -v(输出中应包含 with Xdebug)php -m | grep xdebug(应能看到 xdebug)二 配置 Xdebug 3(Ubuntu 常用)
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.mode=debug 启用调试模式(Xdebug 3 推荐方式)xdebug.client_host 为调试客户端(PhpStorm)地址,本地调试填 127.0.0.1xdebug.client_port 默认 9003,需与 PhpStorm 一致xdebug.start_with_request=yes 让每次请求都尝试连接调试器(也可用触发方式,见下文“常见问题”)三 配置 PhpStorm
四 开始调试与常用操作
五 常见问题与排查
xdebug.client_host 应为 127.0.0.1sudo systemctl restart apache2;Nginx+PHP-FPM:sudo systemctl restart php{version}-fpm && sudo systemctl restart nginx)php -m | grep xdebug 与 phpinfo() 检查 Xdebug 是否加载及配置是否生效xdebug.start_with_request 设为 trigger,访问时在 URL 添加参数:?XDEBUG_TRIGGER=1(或设置 Cookie),即可按需启动调试