要在 PhpStorm 中遠程調試 CentOS 項目,請按照以下步驟操作:
在 CentOS 服務器上,使用以下命令安裝 Xdebug:
sudo yum install php-xdebug
編輯你的 php.ini
文件(通常位于 /etc/php.ini
或 /etc/php/7.x/cli/php.ini
),添加以下配置:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=<your_local_ip>
xdebug.client_port=9003
xdebug.start_with_request=yes
將 <your_local_ip>
替換為你的本地計算機 IP 地址。保存并關閉文件。
重啟你的 Web 服務器(例如 Apache 或 Nginx)以應用更改:
sudo systemctl restart httpd
或
sudo systemctl restart nginx
打開 PhpStorm,然后轉到 “File” > “Settings” > “Languages & Frameworks” > “PHP”。在 “CLI Interpreter” 部分,點擊齒輪圖標,然后選擇 “Add”。輸入一個名稱,選擇 “SSH Interpreter”,然后輸入你的 CentOS 服務器的 IP 地址、用戶名和密碼。
在 “Interpreter” 部分,選擇 “Path to PHP executable”。這應該是你的 CentOS 服務器上的 PHP 可執行文件路徑,例如 /usr/bin/php
。在 “Additional Options” 部分,添加以下參數:
-xdebug.start_with_request=yes
-xdebug.client_host=<your_local_ip>
-xdebug.client_port=9003
將 <your_local_ip>
替換為你的本地計算機 IP 地址。點擊 “Finish” 以保存設置。
在你的項目中設置斷點,以便在調試時暫停執行。
在 PhpStorm 中,轉到 “Run” > “Start Listening for PHP Debug Connections”。然后,在你的瀏覽器中訪問你的 CentOS 項目。當代碼執行到斷點時,PhpStorm 將捕獲并顯示調試信息。
使用 PhpStorm 的調試工具欄來逐步執行代碼、查看變量值等。
完成調試后,轉到 “Run” > “Stop Listening for PHP Debug Connections” 以停止調試會話。