在 Ubuntu + PhpStorm 下配置 Xdebug 一般分为三步:安装 Xdebug、配置 php.ini、配置 PhpStorm。下面以 PHP 8.x + Xdebug 3.x 为例(最常见)。
sudo apt update
sudo apt install php-xdebug
安装后一般会在:
/etc/php/8.x/cli/conf.d/20-xdebug.ini
/etc/php/8.x/apache2/conf.d/20-xdebug.ini
或
/etc/php/8.x/fpm/conf.d/20-xdebug.ini
sudo nano /etc/php/8.x/cli/conf.d/20-xdebug.ini
(如果是 web 调试,改 apache2 或 fpm 下的)
zend_extension=xdebug.so
[Xdebug]
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
⚠️ Xdebug 3 默认端口是 9003(老版本是 9000)
# Apache
sudo systemctl restart apache2
# 或 PHP-FPM
sudo systemctl restart php8.x-fpm
php -v
看到类似:
with Xdebug v3.x
说明成功。
File → Settings → PHP
... → 确保 Xdebug 被识别Settings → PHP → Debug
9003Settings → PHP → Debug → DBGp Proxy
IDE key: PHPSTORM
Host: 127.0.0.1
Port: 9003
工具栏点击:
▶▶ Start Listening for PHP Debug Connections
访问: https://www.jetbrains.com/phpstorm/marklets/
生成:
点击 Start Debug 后访问你的项目。
http://localhost/project/?XDEBUG_SESSION=PHPSTORM
xdebug.mode=debugstart_with_request=yesxdebug.start_with_request=trigger
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
如果你用的是 Docker / WSL / Laravel / Nginx,告诉我,我可以给你针对性配置。