前言
PHP项目使用PhpStudy搭建本地环境后,在PhpStorm中配置Xdebug,之前遇到了很多问题不能配置成功,现在做个笔记记录下配置过程,也为有需要的避免入坑。
配置步骤
1.安装Xdebug 配置
php.ini文件正确的配置如下:
[Xdebug]
xdebug.default_enable=On
xdebug.idekey = "PHPSTORM"
zend_extension=D:/phpstudy_pro/Extensions/php/php5.6.9nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=On
xdebug.trace_output_dir=D:/phpstudy_pro/Extensions/php_log/php5.6.9nts.xdebug.trace
xdebug.profiler_enable=On
xdebug.profiler_output_dir=D:/phpstudy_pro/Extensions/php_log/php5.6.9nts.xdebug.profiler
xdebug.remote_enable=On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9003
xdebug.remote_handler=dbgp
几点说明:
(1)zend_extension为xdebug必要扩展,xdebug官网下载地址:https://xdebug.org/download
(2)xdebug.idekey、remote_host、remote_port需要与phpstorm中设置的一致
(3)有些参数需要设置为on,或者1,代表开启的状态。
***配置是否成功,可以通过phpinfo()查看:
2. PhpStorm配置
(1)打开PhpStorm项目,点击菜单 File -> Settings
(2)PHP本版设置
- 配置Debug port,找到Languages & Frameworks -> PHP -> Debug,特别注意:端口号port要和php.ini中的一致。
- 设置Servers,路径Languages & Frameworks -> PHP -> Servers,这个很重要,代码中配置Edit configurations时会下拉选择,这里要配置正确。
3.配置DBGp Proxy,路径Languages & Frameworks -> PHP -> Debug -> DBGp Proxy,参数要和php.ini保持一致。
3. Edit Configurations配置
(1)在项目中找到找到PhpStorm右上角电话图标,开始监听php debug的链接
(2)然后,点击+号,选择PHP Web Page
(3)注意这里的,Configuration -> Service下拉可以选择之前设置好的Services
4. 配置成功
如果配置顺利,点击右上角的甲虫图标,会有如下显示:
在需要打断点的行前打个圆点,如果xdebug成功会打勾。
如果有数据,则Xdubug成功
写在最后
Google浏览器配合Xdebug,需要在浏览器中下载Xdebug helper扩展,项目开发中保持打开的状态,实时debug
END