温馨提示×

Ubuntu怎么配置PHPStorm

小樊
41
2026-07-16 03:15:08
栏目: 编程语言

在 Ubuntu 上配置 PhpStorm 主要包括 安装、基本配置、PHP 运行环境、调试(Xdebug) 等。下面给你一套从零到可用的完整流程(适用于 Ubuntu 20.04 / 22.04 / 24.04)。


一、安装 PhpStorm

✅ 方法一:官方 Snap(推荐,最简单)

sudo snap install phpstorm --classic

安装完成后,在应用菜单中搜索 PhpStorm 即可启动。


✅ 方法二:官网下载(适合需要指定版本)

  1. 下载
    https://www.jetbrains.com/phpstorm/download/linux

  2. 解压:

tar -xvf PhpStorm-*.tar.gz
  1. 运行:
cd PhpStorm-*/
./bin/phpstorm.sh

(可选)创建桌面快捷方式。


二、首次启动配置

启动后:

  1. 导入设置

    • 第一次使用选 Do not import settings
  2. 选择 UI 主题

    • Light / Darcula(推荐 Darcula)
  3. 安装插件(可选)

    • Chinese (Simplified)(中文语言包)
    • Docker
    • Git

三、配置 PHP 运行环境(关键)

1️⃣ 安装 PHP(Ubuntu)

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

查看版本:

php -v

2️⃣ 在 PhpStorm 中配置 PHP 解释器

  1. 打开:
Settings / Preferences
→ PHP
  1. 点击 ... 设置 PHP interpreter

  2. 选择:

/usr/bin/php

✅ 如果没找到,点 + → From Docker / WSL / System


四、配置 Web 服务器(Nginx / Apache)

✅ 使用 Nginx(推荐)

sudo apt install nginx -y

创建站点目录:

sudo mkdir -p /var/www/phpstorm-test

Nginx 配置示例:

server {
    listen 80;
    server_name localhost;

    root /var/www/phpstorm-test;
    index index.php;

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

重启:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

五、配置 PhpStorm 调试(Xdebug,非常重要)

1️⃣ 安装 Xdebug

sudo apt install php-xdebug

确认:

php -v

2️⃣ 配置 Xdebug

编辑:

sudo nano /etc/php/*/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

重启 PHP-FPM:

sudo systemctl restart php-fpm

3️⃣ PhpStorm 中启用调试

  1. Settings → PHP → Debug

  2. Debug port:9003

  3. 勾选:

    • ✅ Can accept external connections
  4. 点右上角 电话图标(Start Listening)

  5. 浏览器访问 PHP 页面,打断点即可调试 ✅


六、配置 Git(常用)

sudo apt install git -y
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

PhpStorm 会自动识别 Git。


七、常见问题

❓ PhpStorm 中文乱码?

sudo apt install fonts-noto-cjk

❓ 无法识别 PHP?

确认:

which php

❓ 性能慢?

  • 关闭不必要的插件
  • 使用 SSD
  • 增加内存:
Help → Change Memory Settings

八、推荐目录结构

/var/www/project/
├── public/
│   └── index.php
├── src/
└── .git/

如果你愿意,我可以帮你:

  • 配置 Laravel / ThinkPHP
  • Docker + PhpStorm
  • 远程服务器开发
  • 直接给你一份完整示例项目

你现在是 本地开发 还是 服务器开发

0