在CentOS环境下使用PhpStorm调试代码,可按以下步骤进行:
使用yum安装Xdebug:sudo yum install php-xdebug
。
编辑/etc/php.ini
文件,添加以下内容:
[Xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
xdebug.start_with_request=yes
重启PHP服务:sudo systemctl restart php-fpm
。
打开PhpStorm,在File -> Settings
中,选择Languages & Frameworks -> PHP -> Servers
,添加新服务器,设置主机名、端口等,勾选Use path mappings
并配置路径映射。在Languages & Frameworks -> PHP -> Debug
中,设置Debug port为9003,IDE key为PHPSTORM。
在代码中设置断点,点击PhpStorm右上角绿色三角形按钮或按Shift+F9
启动调试模式,在浏览器中访问应用程序,当代码执行到断点时,PhpStorm会自动切换到调试视图,可进行单步调试等操作。