温馨提示×

debian下phpstorm怎么配置

小樊
48
2026-10-02 15:29:03
栏目: 编程语言

在 Debian 下配置 PhpStorm,通常分为 安装、JDK、PHP 环境、调试(Xdebug)、数据库/服务器 几个部分。下面给你一个完整、实用的配置流程。


一、安装 PhpStorm(Debian)

方式一:官方 tar 包(推荐)

# 下载(去官网复制最新链接)
wget https://download.jetbrains.com/webide/PhpStorm-2024.1.tar.gz

# 解压
sudo tar -xzf PhpStorm-*.tar.gz -C /opt/

# 运行
/opt/PhpStorm-*/bin/phpstorm.sh

可创建快捷方式:

sudo ln -s /opt/PhpStorm-*/bin/phpstorm.sh /usr/local/bin/phpstorm

方式二:Snap(适合桌面用户)

sudo apt install snapd
sudo snap install phpstorm --classic

二、Java 环境(PhpStorm 依赖)

PhpStorm 需要 JDK 17+

sudo apt update
sudo apt install openjdk-17-jdk

验证:

java -version

三、配置 PHP 环境

1. 安装 PHP

sudo apt install php php-cli php-fpm php-mysql php-xml php-mbstring php-curl

查看版本:

php -v

2. PhpStorm 中配置 PHP 解释器

  1. 打开 PhpStorm
  2. Settings / Preferences → PHP
  3. CLI Interpreter → +
  4. 选择:/usr/bin/php
  5. 确认 PHP version 显示正常

四、配置 Xdebug(非常重要)

1. 安装 Xdebug

sudo apt install php-xdebug

查看配置文件位置:

php --ini

一般是:

/etc/php/8.x/cli/conf.d/20-xdebug.ini

2. 配置 Xdebug

编辑:

sudo nano /etc/php/8.x/cli/conf.d/20-xdebug.ini

内容示例:

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM

重启 PHP:

sudo systemctl restart php8.x-fpm

3. PhpStorm 中配置 Xdebug

  • Settings → PHP → Debug
  • Debug port:9003
  • DBGp Proxy:
    • IDE key:PHPSTORM
    • Host:127.0.0.1
    • Port:9003

然后:

  • 右上角 → 电话图标(Listen for Debug Connections)
  • 浏览器装 Xdebug Helper 插件

五、Web 服务器(Nginx / Apache)

Nginx 示例(PHP-FPM)

server {
    listen 80;
    root /var/www/html;
    index index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.x-fpm.sock;
    }
}

PhpStorm 中:

  • Settings → PHP → Servers
  • Host: localhost
  • Port: 80
  • Debugger: Xdebug

六、Composer 配置

sudo apt install composer

PhpStorm:

  • Settings → PHP → Composer
  • 勾选 Do not use remote PHP interpreter

七、常用优化

1. 文件监听(可选)

sudo apt install inotify-tools

2. 字体 & 主题

  • Settings → Editor → Font
  • 推荐:JetBrains Mono

八、常见问题

PhpStorm 启动卡?

export _JAVA_AWT_WM_NONREPARENTING=1

Xdebug 不生效?

  • 确认 xdebug.mode=debug
  • 确认端口一致
  • 浏览器插件 IDE key = PHPSTORM

如果你愿意,可以告诉我:

  • 是 桌面版 Debian 还是 服务器 + 远程开发
  • PHP 版本
  • 是否用 Docker

我可以给你 更针对性的配置方案。

0 踩