以下是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。