以下是在CentOS上使用PhpStorm进行远程调试的技巧及关键步骤:
安装Xdebug扩展
通过PECL安装(推荐):
sudo yum install php-devel php-pear autoconf gcc pecl install xdebug 或手动下载编译(需指定路径)。
修改php.ini配置
添加以下参数(确保与PhpStorm端口一致,如9000):
zend_extension=/path/to/xdebug.so xdebug.remote_enable=1 xdebug.remote_host=<PhpStorm机器IP> # 本地调试可填localhost xdebug.remote_port=9000 xdebug.idekey=PHPSTORM xdebug.remote_autostart=1 # 可选,自动启动调试 重启PHP-FPM生效:
sudo systemctl restart php-fpm 验证安装
创建phpinfo.php文件,访问页面检查Xdebug是否启用。
设置PHP解释器
/usr/bin/php)。配置调试服务器
xdebug.remote_port一致(如9000)开启监听与调试
http://server-ip:port),触发断点。防火墙设置
确保CentOS开放Xdebug端口(默认9000):
sudo firewall-cmd --add-port=9000/tcp --permanent sudo firewall-cmd --reload 验证端口是否开放:sudo firewall-cmd --list-ports。
路径映射问题
若远程与本地路径不一致,需在PhpStorm的Servers配置中手动映射,否则无法正确断点。
SSH隧道(可选)
若需通过SSH连接远程服务器,可在PhpStorm的DBGp Proxy中配置SSH隧道参数,避免直接暴露端口。
调试工具辅助
xdebug.remote_port和PhpStorm配置为其他端口(如9001)。xdebug.remote_host是否为PhpStorm机器的正确IP,或尝试关闭防火墙测试。通过以上步骤,可高效完成CentOS上的PhpStorm远程调试,适用于LNMP/LAMP等环境。