在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.5.tgz
tar xvf xdebug-2.5.5.tgz
cd xdebug-2.5.5
# 配置并编译安装Xdebug
phpize
./configure --with-php-config=/usr/bin/php-config
make
sudo make install
# 编辑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_handler=dbgp" | 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,配置远程调试设置。
配置PHP解释器和服务器:
File
-> Settings
(Windows/Linux)或 PhpStorm
-> Preferences
(macOS)。Languages & Frameworks
-> PHP
-> CLI Interpreter
。点击右侧的齿轮图标,然后选择 Add
。输入一个名称,选择 SSH Interpreter
,然后输入你的CentOS服务器的IP地址、用户名和密码。Interpreter
部分,选择 Path to PHP executable
。这应该是你的CentOS服务器上的PHP可执行文件路径,例如 /usr/bin/php
。Additional Options
部分,添加以下参数:-xdebug.start_with_request=yes
-xdebug.client_host=your_local_ip
-xdebug.client_port=9000
将 your_local_ip
替换为你的本地计算机IP地址。配置调试服务器:
Run
-> Edit Configurations
。PHP Web Page
。Server
:选择你配置的PHP解释器。Start URL
:设置为 http://your_server_ip:9000
。Debugger
:选择 Xdebug
。启动远程调试:
Run
-> Debug
。从下拉菜单中选择你之前配置的远程调试服务器。确保在浏览器的插件商店中安装了Xdebug Helper(推荐使用Chrome插件),并配置其IDE Key为 PHPSTORM
。
如果一切配置正确,当浏览器访问PHP页面时,PhpStorm会自动捕获到调试请求并暂停在设置的断点处。此时,你可以使用PhpStorm的调试功能进行单步调试、查看变量等。
通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。如果有任何问题,请检查配置文件和端口设置是否正确。