首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

Eclipse PDT + Xdebug 搭建 PHP 調試環境全流程(Linux/Ubuntu)

     編輯:PHP 相關知識

環境準備

  • JDK/JRE(Eclipse 運行基礎)
  • PHP 開發環境(含 phpize、php-dev)
  • Apache/Nginx + PHP

步驟詳解

1. 安裝 Eclipse PDT

  • 官網下載 Eclipse IDE for PHP Developers(含 PDT)
  • 或標準版 Eclipse → Help → Install New Software → 添加 PDT 更新源

2. 編譯安裝 Xdebug 擴展

# 下載源碼
wget https://xdebug.org/files/xdebug-3.x.x.tgz
tar -xzf xdebug-3.x.x.tgz
cd xdebug-3.x.x

# 編譯
phpize
./configure --enable-xdebug
make
sudo make install

3. 配置 php.ini / xdebug.ini

; /etc/php/8.x/mods-available/xdebug.ini
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.client_host=localhost
xdebug.client_port=9003
xdebug.idekey=ECLIPSE_DBGP
xdebug.log=/tmp/xdebug.log

重啟 Apache/PHP-FPM:sudo systemctl restart apache2

4. Eclipse 調試配置

  1. Window → Preferences → PHP → Debug:Debugger 選 XDebug
  2. PHP → PHP Servers → New:Name 隨意,Base URL 填項目訪問地址(如 https://localhost/myproject),設為 Default
  3. PHP → PHP Executables → Add:Name 隨意,PHP Executable 填 /usr/bin/php,php.ini 路徑,SAPI Type 選 CLI,Debugger 選 XDebug

5. 實戰調試

  • 創建 PHP Project,放入 Apache DocumentRoot
  • 新建 PHP 文件,寫代碼,雙擊行號打斷點
  • 右鍵文件 → Debug As → PHP Web Application
  • Debug 視圖查看變量、堆棧、表達式、Superglobals($_GET/$_POST/$_SESSION)

常見坑點

  • Server 配置 Path Mapping
  • 現象原因解決
    斷點不生效xdebug.mode 缺少 debug設置 xdebug.mode=debug
    端口衝突9003 被佔用修改 xdebug.client_port
    路徑映射錯誤Server Path Mapping 未配置
    SAPI Type 調不了CLI/Web 混淆調試 Web 用 Web Server 配置,CLI 用 CLI

    替代方案

    • VS Code + PHP Debug:輕量、配置簡單、生態豐富
    • PhpStorm:開箱即用、智能提示強、收費
    • Docker + Xdebug:環境隔離、團隊統一

    Eclipse PDT 雖然經典,但對新手配置門檻較高。建議優先嘗試 VS Code,體驗更現代化。

    1. 上一篇文章:
    2. 下一篇文章:
    Copyright © 程式碼之家 All Rights Reserved