在CentOS上使用PhpStorm进行远程调试PHP代码,可以按照以下步骤进行配置:
首先,确保在远程服务器上安装了Xdebug扩展。可以通过以下命令安装:
sudo pecl install xdebug
然后,编辑php.ini
文件(通常位于/etc/php.ini
或/etc/php/7.x/apache2/php.ini
),添加以下配置:
zend_extension=/path/to/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.remote_autostart = 1
xdebug.remote_host = 127.0.0.1 # 这里应该是你的PhpStorm所在的机器IP
xdebug.remote_port = 9000 # 默认调试端口
xdebug.idekey = PHPSTORM # 与PhpStorm中配置的相同
重启Apache服务器以应用配置:
sudo systemctl restart httpd
File
-> Settings
(或PhpStorm
-> Preferences
on macOS)。Languages & Frameworks
-> PHP
-> Debug
。Xdebug
部分,选择Xdebug
作为调试引擎,并配置监听端口(默认是9000)。OK
保存设置。Add Configuration
(绿色的加号按钮)。+
号,选择PHP Remote Debug
。PHPSTORM
。OK
保存配置。Start Listening for PHP Debug Connections
按钮,确保调试监听已经启动。Toggle Line Breakpoint
设置断点。<?php
phpinfo();
?>
确保在浏览器的插件商店中安装了Xdebug Helper(推荐使用Chrome插件),并配置其IDE Key为PHPSTORM
。
如果一切配置正确,当浏览器访问PHP页面时,PhpStorm会自动捕获到调试请求并暂停在设置的断点处。此时,你可以使用PhpStorm的调试功能进行单步调试、查看变量等。
php.ini
中修改xdebug.remote_port
为一个不同的端口,并在PhpStorm中相应修改监听端口。通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。希望这些信息对你有所帮助。