以下是CentOS環境下使用PhpStorm遠程調試PHP代碼的步驟:
安裝Xdebug擴展
sudo yum install php-devel gcc make
sudo pecl install xdebug
php.ini
,添加以下配置(需根據實際路徑調整):zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=<PhpStorm機器IP> # 或使用remote_connect_back=1自動獲取
xdebug.remote_port=9003 # 與PhpStorm配置一致
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
sudo systemctl restart php-fpm
配置PhpStorm
File > Settings > Languages & Frameworks > PHP > CLI Interpreter
,選擇服務器PHP路徑(如/usr/sbin/php-fpm
)。Run > Edit Configurations > + > PHP Remote Debug
,填寫服務器名稱、IP、端口(與xdebug.remote_port
一致),選擇對應的PHP解釋器。Use path mappings
,將本地項目路徑映射到服務器路徑(如/var/www/html
)。啟動調試
Start Listening for PHP Debug Connections
(蟲子圖標)。http://服務器IP:9003
),觸發斷點后進入調試模式。可選:SSH隧道(跨網絡使用)
ssh -R 9003:localhost:9003 user@服務器IP
Deployment
中勾選Use SSH tunnel
,配置對應端口。注意事項:
remote_connect_back=1
,需確保服務器能訪問本地IP。