在CentOS下使用PhpStorm进行远程调试PHP代码,可以按照以下步骤进行配置:
首先,需要在你的CentOS服务器上安装Xdebug扩展。可以通过以下命令来完成安装:
sudo yum install php-devel gcc make
cd /usr/src
wget http://xdebug.org/files/xdebug-2.5.5.tgz
tar xvf xdebug-2.5.5.tgz
cd xdebug-2.5.5
./configure --with-php-config=/usr/bin/php-config
make
sudo make install
然后,编辑php.ini
文件,添加以下配置:
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9003
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
重启PHP-FPM服务以使配置生效:
sudo service php-fpm restart
打开PhpStorm,进入File
-> Settings
(或PhpStorm
-> Preferences
on macOS)。
Languages & Frameworks
-> PHP
-> CLI Interpreter
中,选择与服务器上安装的PHP版本相匹配的解释器。PHP
-> Servers
中,点击+
号,添加一个新的服务器配置。填写服务器名称、主机名(或IP地址)和端口(与php.ini
中的xdebug.remote_port
一致,例如9003)。Deployment
选项卡中,点击+
号,选择FTP
、SFTP
或FTPS
,根据你的服务器配置选择合适的协议。PHP
-> Debug
中,确保Debug port
与php.ini
中的xdebug.remote_port
一致。OK
保存配置。Shift + F9
)开始调试。如果你的服务器和本地机器不在同一网络中,可以使用SSH隧道来安全地连接到服务器。在Windows上,可以使用PuTTY等工具创建SSH隧道。
例如,使用PuTTY创建SSH隧道:
Connection
-> SSH
-> Tunnels
中,输入本地端口(例如9003)和远程端口(例如9003),然后点击Add
。Open
开始连接。在PhpStorm中配置SSH隧道:
Deployment
选项卡中,勾选Use path mappings
。SSH/SSL
选项卡中,配置SSH隧道,输入本地端口和远程端口。完成以上步骤后,你就可以在PhpStorm中进行远程调试了。如果在配置过程中遇到问题,可以参考PhpStorm的官方文档或搜索相关的教程资源。。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>