温馨提示×

CentOS下PHPStorm怎么配置

小樊
34
2026-08-03 17:37:31
栏目: 编程语言

CentOS 下配置 PHPStorm 主要包含 安装运行环境、配置 PHP、配置服务器/调试、可选的中文与性能优化 等几个部分。下面按“从零开始”给你一份完整、实用的配置指南。


一、安装 PHPStorm(CentOS)

方式一:官方下载(推荐)

  1. 下载 PHPStorm
    https://www.jetbrains.com/phpstorm/download/#section=linux

  2. 解压并安装

tar -xzf PhpStorm-*.tar.gz -C /opt/
cd /opt/PhpStorm-*/
./bin/phpstorm.sh
  1. 创建桌面快捷方式(可选)
ln -s /opt/PhpStorm-*/bin/phpstorm.sh /usr/local/bin/phpstorm

方式二:Toolbox(推荐长期用)

# 下载 JetBrains Toolbox
# https://www.jetbrains.com/toolbox-app/

适合管理多个 JetBrains IDE。


二、安装 PHP(CentOS)

CentOS 7

yum install epel-release -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php81
yum install php php-cli php-fpm php-json php-mysql php-xml php-mbstring php-curl -y

CentOS 8 / Stream

dnf install php php-cli php-fpm php-json php-mysqlnd php-xml php-mbstring php-curl -y

验证:

php -v

三、PHPStorm 基本配置

1️⃣ 配置 PHP 解释器

  1. 打开 PHPStorm
  2. File → Settings → PHP
  3. 点击 CLI Interpreter → +
  4. 选择 From Docker, Vagrant, SSH... 或 Local
  5. 设置:
    • PHP executable:
      /usr/bin/php
      
  6. 应用并保存

✅ 成功后你会看到 PHP 版本信息


2️⃣ 配置项目运行环境

本地运行(PHP Built-in Server)

  1. Run → Edit Configurations
  2. 点击 + → PHP Built-in Web Server
  3. 配置:
    • Host:localhost
    • Port:8000
    • Document root:项目 public 或根目录
  4. 运行

浏览器访问:

http://localhost:8000

四、配置 Xdebug(调试必备)

1️⃣ 安装 Xdebug

yum install php-xdebug -y

或手动:

pecl install xdebug

2️⃣ 配置 php.ini

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

重启 PHP-FPM 或 Apache:

systemctl restart php-fpm

3️⃣ PHPStorm 配置 Xdebug

  1. Settings → PHP → Debug
  2. Debug port:9003
  3. 勾选:
    • ✅ Can accept external connections
  4. Settings → PHP → Servers
    • 添加服务器
    • Name:localhost
    • Host:localhost
    • Port:808000
    • Debugger:Xdebug

4️⃣ 测试调试

  1. 在代码中打断点
  2. 点击电话图标(Listen for Debug Connections)
  3. 浏览器访问
  4. 触发断点 ✅

五、配置代码风格(推荐)

Settings → Editor → Code Style → PHP

  • 推荐:PSR-12
  • 自动格式化:Ctrl + Alt + L

六、中文语言包(可选)

  1. File → Settings → Plugins
  2. 搜索:Chinese (Simplified) Language Pack
  3. 安装并重启

七、常见问题

❌ PHPStorm 启动慢

# 增加内存
编辑:
/opt/PhpStorm/bin/phpstorm64.vmoptions
-Xms512m
-Xmx2048m

❌ PHP 命令找不到

which php

PHPStorm 中填写 完整路径


八、推荐插件

  • PHP Annotations
  • Symfony Support
  • Laravel Idea(Laravel 项目)
  • .env files support
  • GitToolBox

九、典型场景配置总结

场景 推荐配置
本地开发 PHP Built-in Server
Laravel PHP CLI + Xdebug
API 调试 Postman + Xdebug
远程服务器 SSH Interpreter

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

  • ✅ CentOS 版本(7 / 8 / Stream)
  • ✅ PHP 版本
  • ✅ 是否 Laravel / ThinkPHP / 原生 PHP
  • ✅ 本地 or 远程服务器

我可以给你 针对你环境的一键配置方案

0