在CentOS上使用PhpStorm进行远程调试PHP代码,可以按照以下步骤进行配置:
安装必要的开发工具和库:
sudo yum install gcc php-devel php-pear autoconf
下载并解压Xdebug:
wget http://xdebug.org/files/xdebug-2.5.0.tgz
tar 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_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
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
(与php.ini中的配置一致)。Xdebug
。Run -> Debug
。从下拉菜单中选择你之前配置的远程调试服务器。PhpStorm将连接到远程服务器,并在设置的断点处暂停执行。http://your-server-ip:9000/your-script.php
。PHPSTORM
。通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。如果有任何问题,请检查配置文件和端口设置是否正确。