温馨提示×

ubuntu phpstorm怎样配置

小樊
39
2026-10-07 21:36:19
栏目: 编程语言

下面按**在 Ubuntu 上安装并配置 PHPStorm(实际叫 PhpStorm)**的完整流程来说明,适合本地开发环境。


一、安装 PhpStorm

方式 1:通过 JetBrains Toolbox(推荐)

# 下载 Toolbox
wget https://download.jetbrains.com/toolbox/jetbrains-toolbox-2.0.2.tar.gz

# 解压
tar -xzf jetbrains-toolbox-*.tar.gz

# 运行
./jetbrains-toolbox

然后在 Toolbox 中安装 PhpStorm。


方式 2:直接下载 PhpStorm

wget https://download.jetbrains.com/webide/PhpStorm-2024.1.tar.gz
tar -xzf PhpStorm-*.tar.gz
cd PhpStorm-*/
./bin/phpstorm.sh

二、安装 PHP 运行环境

1. 安装 PHP

sudo apt update
sudo apt install php php-cli php-fpm php-mysql php-xdebug

查看版本:

php -v

2. 配置 PHP CLI 解释器

PhpStorm 需要知道 PHP 在哪:

which php
# 通常是 /usr/bin/php

三、PhpStorm 基础配置

1. 设置 PHP 解释器

  1. 打开 PhpStorm
  2. File → Settings → PHP
  3. CLI Interpreter → +
  4. 选择 From Docker / WSL / Local
  5. PHP executable:
    /usr/bin/php
    
  6. 点击 Apply

2. 配置 Xdebug(调试用)

编辑 php.ini:

php --ini
sudo nano /etc/php/8.x/cli/php.ini

添加:

[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

测试:

php -m | grep xdebug

PhpStorm 中:

  • Settings → PHP → Debug
  • Debug port: 9003

四、配置 Web 服务器(可选)

使用 PHP 内置服务器(最简单)

php -S localhost:8000

PhpStorm:

  • Run → Edit Configurations
  • 添加 PHP Built-in Web Server
  • Host: localhost
  • Port: 8000

或使用 Nginx + PHP-FPM

sudo apt install nginx

配置:

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

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

五、常用插件推荐

  • PHP Annotations
  • Laravel / Symfony Support
  • Docker
  • GitToolBox

六、常见问题

❌ 字体模糊
→ 安装 JDK 并启用 Anti-aliased

❌ 无法调试
→ 检查 Xdebug 端口、防火墙、start_with_request


如果你告诉我:

  • Ubuntu 版本
  • PHP 版本
  • 是否用 Docker / Laravel / 远程服务器

我可以给你更精确的配置方案。

0 踩