在CentOS下使用PhpStorm进行远程调试PHP代码,可以按照以下步骤进行:
首先,确保你的CentOS系统上已经安装了PHP和PHP-FPM。然后,安装Xdebug扩展。
# 安装必要的开发工具和库
sudo yum install gcc php-devel php-pear autoconf
# 下载并解压Xdebug
wget http://xdebug.org/files/xdebug-2.5.0.tgz
xvzf xdebug-2.5.0.tgz
cd xdebug-2.5.0
# 配置并编译安装Xdebug
phpize
./configure --enable-xdebug
make
sudo cp modules/xdebug.so /usr/lib64/php/modules/xdebug.so
# 编辑php.ini文件
echo "zend_extension=/usr/lib64/php/modules/xdebug.so" | sudo tee -a /etc/php.ini
echo "xdebug.remote_enable=1" | sudo tee -a /etc/php.ini
echo "xdebug.remote_host=127.0.0.1" | sudo tee -a /etc/php.ini
echo "xdebug.remote_port=9000" | sudo tee -a /etc/php.ini
echo "xdebug.idekey=PHPSTORM" | sudo tee -a /etc/php.ini
echo "xdebug.remote_autostart=1" | sudo tee -a /etc/php.ini
# 重启PHP-FPM
sudo systemctl restart php-fpm
打开PhpStorm,配置远程调试设置。
File
-> Settings
(或 PhpStorm
-> Preferences
on macOS)。Languages & Frameworks
-> PHP
-> CLI Interpreter
。点击右侧的齿轮图标,然后选择 PHP Executable
,浏览到你的PHP-FPM可执行文件路径(通常在 /usr/sbin/php-fpm
)。Run
-> Edit Configurations
。点击左上角的加号(+),选择 PHP Web Page
。在右侧配置面板中,填写以下信息:
http://your-server-ip:9000
。Xdebug
。Run
-> Debug
。从下拉菜单中选择你之前配置的远程调试服务器。PhpStorm将连接到远程服务器,并在设置的断点处暂停执行。在PhpStorm中,打开你想要调试的项目。在代码中设置断点,例如在 index.php
文件的第10行。点击工具栏上的远程调试按钮(一个绿色的虫子图标),开始监听调试请求。在浏览器中访问你的PHP页面,例如 http://your-server-ip:9000/your-script.php
。当代码执行到断点时,PhpStorm会自动切换到调试视图,你可以进行单步调试、查看变量等。
gbdpproxy
作为调试代理。通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。如果有任何问题,请检查配置文件和端口设置是否正确。