在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 tar xvf 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 标签页中,点击 + 号,添加一个新的服务器配置。 Host: 127.0.0.1(或你的服务器IP)Port: 9000Use path mappings: 勾选,并设置本地项目路径到远程项目路径的映射。OK 保存设置。index.php 文件的第10行。http://your-server-ip:9000/your-script.php。通过以上步骤,你就可以在CentOS上使用PhpStorm进行远程调试PHP代码了。