温馨提示×

ubuntu phpstorm怎样配置php

小樊
43
2026-10-19 14:30:41
栏目: 编程语言

在 Ubuntu 上用 PhpStorm 配置 PHP,主要涉及 PHP 解释器(CLI) 和 运行/调试环境。下面按最常见情况一步步说明。


一、先确认 Ubuntu 已安装 PHP

1. 安装 PHP(如未安装)

sudo apt update
sudo apt install php php-cli

2. 查看 PHP 是否可用

php -v

能看到版本号说明安装成功。


二、PhpStorm 中配置 PHP 解释器

1. 打开 PhpStorm 设置

  • File → Settings(或 Ctrl + Alt + S)
  • 如果是项目级:
    Settings → PHP

2. 配置 CLI Interpreter

在 PHP 页面中:

  • 点击 CLI Interpreter 右侧的 ...
  • 点击 + → From Docker / Local
  • 选择 Local
  • 路径一般填:
    /usr/bin/php
    
    (可用 which php 查看)

✅ 配置完成后,下方会显示 PHP 版本信息


三、配置 PHP 运行(Run / Debug)

方式一:直接运行 PHP 脚本(CLI)

  1. 打开一个 .php 文件
  2. 右上角点击 Add Configuration
  3. 选择 PHP Script
  4. 设置:
    • File:你的 index.php
    • Interpreter:刚才配置的 PHP
  5. 点击 Run

方式二:通过内置服务器(适合 Web 项目)

php -S localhost:8000

然后在浏览器访问:

http://localhost:8000

或在 PhpStorm 中:

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

四、常用扩展安装(可选)

sudo apt install php-mbstring php-xml php-curl php-mysql

安装后重启 PhpStorm 或重新选择 interpreter。


五、常见问题

1. PhpStorm 找不到 PHP

  • 确认 php -v 能运行
  • 使用绝对路径 /usr/bin/php

2. Xdebug(调试用)

如需我也可以教你 Ubuntu + PhpStorm + Xdebug 的完整配置。


如果你告诉我:

  • 是 CLI 项目 / Web 项目 / Laravel
  • 是否要用 Docker / Xdebug

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

0 踩