在 Ubuntu 上设置 PHPStorm,通常包括安装、基础配置、PHP 环境、调试(Xdebug)、快捷键/中文等。下面按步骤说明(以 PHPStorm 2023+ 为例,老版本差别不大)。
tar -xzf PhpStorm-*.tar.gz -C /opt/
/opt/PhpStorm-*/bin/phpstorm.sh
/opt/PhpStorm-*/bin/phpstorm.sh
# 启动后:Tools → Create Desktop Entry
sudo snap install phpstorm --classic
Do not importChinese (Simplified)sudo apt update
sudo apt install php php-cli
php -v
File → Settings → PHP
+/usr/bin/phpsudo apt install php-xdebug
查看路径:
php --ini
编辑:
sudo nano /etc/php/8.x/cli/php.ini
末尾添加:
[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
重启:
sudo systemctl restart apache2
# 或 php-fpm
Settings → PHP → Debug
9003Can accept external connectionsSettings → PHP → Servers
Settings → Editor → Font
推荐:
Settings → Tools → Actions on Save
Settings → PHP → Code Insight
❓ PHP 解释器找不到
which php
确认路径填写正确
❓ Xdebug 不生效
php -m | grep xdebug如果你愿意,可以告诉我:
我可以给你更精确的一步步配置。