温馨提示×

centos如何配置phpstorm

小樊
38
2026-07-20 05:30:06
栏目: 编程语言

CentOS 上配置 PhpStorm 主要包括 安装 PhpStorm配置 PHP 运行环境(PHP、Web 服务器、调试) 等步骤。下面我按**最常见场景(CentOS 7/8 + PHP + Nginx/Apache + PhpStorm)**给你一个完整配置指南。


一、安装 PhpStorm(CentOS)

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

  1. 下载 PhpStorm

    cd /opt
    wget https://download.jetbrains.com/webide/PhpStorm-2024.1.tar.gz
    
  2. 解压

    tar -zxvf PhpStorm-*.tar.gz
    
  3. 运行

    cd PhpStorm-*/
    ./bin/phpstorm.sh
    
  4. (可选)创建桌面快捷方式

    ./bin/phpstorm.sh & 
    

    然后在 PhpStorm 中:

    Tools → Create Desktop Entry
    

二、安装 PHP(CentOS)

CentOS 7(Remi 仓库)

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

CentOS 8 / Stream

dnf install -y epel-release
dnf module enable php:8.1
dnf install -y php php-cli php-fpm php-mysql php-xml php-mbstring

检查版本:

php -v

三、配置 Web 服务器(Nginx 示例)

安装 Nginx

yum install -y nginx
systemctl start nginx
systemctl enable nginx

配置 PHP-FPM

systemctl start php-fpm
systemctl enable php-fpm

编辑:

vi /etc/nginx/conf.d/php.conf

示例配置:

server {
    listen 80;
    server_name localhost;
    root /var/www/html;

    location / {
        index index.php index.html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

重启:

systemctl restart nginx

测试:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

浏览器访问:

http://服务器IP/info.php

四、PhpStorm 配置 PHP 解释器

  1. 打开 PhpStorm
  2. 进入:
    File → Settings → PHP
    
  3. 点击 CLI Interpreter+
  4. 选择:
    • From Docker / Vagrant / WSL(如果有)
    • Other Local
  5. PHP 路径一般:
    /usr/bin/php
    
  6. 点击 OK

五、配置 Xdebug(调试必备)

1️⃣ 安装 Xdebug

yum install -y php-xdebug

或手动:

pecl install xdebug

2️⃣ 配置 xdebug.ini

vi /etc/php.d/99-xdebug.ini

内容示例:

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:

systemctl restart php-fpm

3️⃣ PhpStorm 启用 Xdebug

  1. Settings → PHP → Debug
  2. Debug port:9003
  3. ✅ 勾选:
    • Can accept external connections
  4. 点击 Validate
  5. 设置断点 → 浏览器访问 → 开始调试

六、配置项目路径(非常重要)

如果 PhpStorm 在 Windows / macOS,代码在 CentOS

✅ 推荐方式:

  • 使用 SFTP
  • Samba / NFS

PhpStorm 配置远程服务器

Settings → Deployment → + SFTP

填写:

  • Host:CentOS IP
  • Root path:/var/www/html
  • Mapping:本地 ↔ 远程

七、常见问题

❌ 端口被防火墙拦截

firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload

❌ PHP 不识别

which php

八、总结流程

✅ CentOS
✅ PHP + Nginx/FPM
✅ PhpStorm 配置 PHP Interpreter
✅ Xdebug 调试
✅ 项目路径映射


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

  • ✅ CentOS 版本(7 / 8 / Stream)
  • ✅ PhpStorm 是本机还是 Windows 远程连 CentOS
  • ✅ 是否需要 Docker / 多 PHP 版本

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

0