温馨提示×

centos如何连接phpstorm

小樊
47
2026-09-15 01:04:51
栏目: 编程语言

在 CentOS 上“连接 PhpStorm”通常有几种常见场景,下面按最常见需求给你说明,你可以对号入座。


一、PhpStorm 在 Windows / macOS,CentOS 作为远程服务器(最常用)

方式 1:SFTP / SSH 远程开发(推荐)

适用于:在 CentOS 上运行 PHP,本地用 PhpStorm 写代码

1. CentOS 准备

# 安装并启动 SSH
sudo yum install openssh-server
sudo systemctl start sshd
sudo systemctl enable sshd

# 确认防火墙
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

2. PhpStorm 配置

  1. Tools → Deployment → Configuration
  2. 添加 SFTP
  3. 填写:
    • Host:CentOS IP
    • Port:22
    • User / Password 或 Key
  4. 设置根路径(如 /var/www/html)
  5. 勾选 Automatic Upload

✅ 这样本地保存即同步到 CentOS


方式 2:Remote Interpreter(PHP 解释器在 CentOS)

适用于:用 CentOS 的 PHP 运行 / 调试

  1. Settings → PHP
  2. CLI Interpreter → + → Remote
  3. 选择 SSH 配置
  4. 指定 PHP 路径(通常 /usr/bin/php)

✅ 可在本地断点调试 CentOS 上的 PHP


二、在 CentOS 上直接运行 PhpStorm(图形界面)

前提

CentOS 需有桌面环境(GNOME / KDE)

# 安装 JDK
sudo yum install java-11-openjdk

# 下载 PhpStorm
cd /opt
sudo unzip PhpStorm-*.tar.gz
cd PhpStorm-*/bin
./phpstorm.sh

⚠️ 服务器通常不建议这样做


三、CentOS 作为调试服务器(Xdebug)

CentOS 安装 Xdebug

sudo yum install php-xdebug

php.ini 示例:

[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=你的本地IP
xdebug.client_port=9003

PhpStorm:

  • Settings → PHP → Debug
  • 端口 9003
  • 开启 Start Listening for PHP Debug Connections

四、常见连接方式总结

目的 推荐方式
写代码同步 SFTP Deployment
用 CentOS PHP Remote Interpreter
断点调试 Xdebug + SSH
图形界面 本地电脑运行 PhpStorm

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

  • ✅ PhpStorm 在哪(Win / Mac / CentOS)
  • ✅ 想“写代码 / 运行 / 调试”
  • ✅ CentOS 版本(7 / 8 / Stream)

我可以直接给你一步一步配置图级别教程。

0 踩