在CentOS上使用PhpStorm进行远程调试PHP代码,需要配置Xdebug和PhpStorm。以下是详细的步骤:
首先,确保你的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
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_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
-> Xdebug
。Debug
标签页中,设置Debug port
为9000
(与php.ini中的配置一致)。Servers
标签页中,点击+
号,添加一个新的服务器配置。
127.0.0.1
(或你的服务器IP)9000
OK
保存设置。index.php
文件的第10行。http://your-server-ip:9000/your-script.php
。通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。如果有任何问题,请检查配置文件和端口设置是否正确。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>