Centos下PHP配置sublime+xdebug

1.安装XDebug扩展

可以进入XDebug官网下载相应版本的xdebug。如果不能够确定需要选择的版本号,可以打印phpinfo,并且右键查看源码并进行复制。

粘贴到http://xdebug.org/wizard.php,既可以查看到推荐的XDebug版本。

下载dll文件,粘贴到php的ext目录下。并修改php.ini,添加如下:

  1. [XDebug]  
  2. zend_extension_ts = e:\php\ext\php_xdebug-2.2.3-5.2-vc9.dll  
  3. xdebug.profiler_enable=on  
  4. xdebug.trace_output_dir="f:\xdebug"  
  5. xdebug.profiler_output_dir="f:\xdebug"  
  6. xdebug.remote_enable = on  
  7. xdebug.remote_host = 127.0.0.1  
  8. xdebug.remote_port = 9000  

2.Sublime安装xdebug

下载的路径为:https://github.com/martomo/SublimeTextXdebug

下载后的文件夹,放入sublime->preference->browse packages,重启sublime,即可以看到preference->package setting中有xdebug

用ctrl+shift+p调出搜索框,输入xdebug既可以看到xdebug相关的功能


3.firefox安装xdebug

firefox的xdebug扩展为easiest xdebug,路径为:https://addons.mozilla.org/zh-cn/firefox/addon/the-easiest-xdebug/

安装完后,浏览器右下角有个绿色的甲壳虫,点击这个甲壳虫,它有颜色时即为debug状态


4.调试

1.xdebug可以选择watch变量

2.xdebug可以在代码中设置断点

3.xdebug可以start

4.在firefox debug状态下运行,即可以看到断点处的输出;并且可以进行单步调试


快捷键说明如下:

Start/Stop debugging session
  • Start Debugging - Ctrl+Shift+F9 or ⌘+Shift+F9
  • Start Debugging (Launch Browser)
  • Restart Session
  • Stop Debugging - Ctrl+Shift+F10 or ⌘+Shift+F10
  • Stop Debugging (Launch Browser)
  • Stop Debugging (Close Windows)
Breakpoints
  • Add/Remove Breakpoint - Ctrl+F8 or ⌘+F8
  • Set Conditional Breakpoint - Shift+F8
  • Clear Breakpoints
  • Clear All Breakpoints
Watch expressions
  • Set Watch Expression
  • Edit Watch Expression
  • Remove Watch Expression
  • Clear Watch Expressions
Session commands
  • Evaluate
  • Execute
  • Status
Continuation commands
  • Run - Ctrl+Shift+F5 or ⌘+Shift+F5
  • Run To Line
  • Step Over - Ctrl+Shift+F6 or ⌘+Shift+F6
  • Step Into - Ctrl+Shift+F7 or ⌘+Shift+F7
  • Step Out - Ctrl+Shift+F8 or ⌘+Shift+F8
  • Stop
  • Detach
Other
  • Restore Layout / Close Windows - Ctrl+Shift+F11 or ⌘+Shift+F11
  • Settings - Default
  • Settings - User


安装步骤:
1、复制到任意一个独立的目录中,用 tar -xzf xdebug-2.0.0RC3.tgz 解压;
2、cd xdebug-2.0.0RC3 进入刚解压的目录;
3、运行/usr/bin/phpize
4、./configure --enable-xdebug --with-php-config=/usr/bin/php-config配置
5、make 编译

编译成功后,会在当前目录的 modules 目录下生成 xdebug.so 文件,把这个文件复制到/usr/lib/php/modules/ 下,然后配置 /etc/php.ini,在尾部加入如下内容:

[Xdebug]
zend_extension_ts = "/usr/lib/php/modules/xdebug.so"
zend_extension = "/usr/lib/php/modules/xdebug.so"
xdebug.auto_trace = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.trace_output_dir = "/tmp"
xdebug.profiler_output_dir = "/tmp"
xdebug.dump.GET = *
xdebug.dump.POST = *
xdebug.dump.COOKIE = *
xdebug.dump.SESSION = *
xdebug.var_display_max_data = 4056
xdebug.var_display_max_depth = 5

然后重启 apache 即可。


3、xdebug配置说明:http://xdebug.org/docs/all_settings

xdebug.auto_trace = 1

是否允许Xdebug跟踪函数调用,跟踪信息以文件形式存储,默认值为0

collect_params = 1

是否允许Xdebug跟踪函数参数,默认值为0

xdebug.collect_return = 1

是否允许Xdebug跟踪函数返回值,默认值为0

xdebug.profiler_enable = 1

打开xdebug的性能分析器,以文件形式存储,这项配置是不能以ini_set()函数配置的,默认值为0

xdebug.profiler_output_dir

性能分析文件的存放位置,默认值为/tmp

xdebug.profiler_output_name

性能分析文件的命名规则,默认值为cachegrind.out.%p

xdebug.trace_output_dir

函数调用跟踪信息输出文件目录,默认值为/tmp

xdebug.trace_output_name


首先需要下载xdebug,我们可以 点此 下载xdebug-2.2.5.tgz,或者在 xdebug官网 下载相应的安装包。并且确定PHP的安装目录,假设php安装目录为/usr/local/php。

安装xdebug

对于xdebug可以独立于PHP进行编译安装,但是我们必须拥有执行phpize的权限,并且对于php-config也拥有相应的权限,此二者所在目录为

/usr/local/php/bin/phpize/usr/local/php/bin/php-config

接下来按照以下步骤安装xdebug

1. # tar –zxvf xdebug-2.2.5.tg //解压源码包,但是需要注意的是没有必要把源码解压到PHP的源码包中,解压到独立的目录

2. # cd xdebug-2.2.5  //进入源码目录中

3. Xdebug]# /usr/local/php/bin/phpize //运行phpize命令,运行此命令以后会在源码目录中产生configure等文件

4. Xdebug]# ./configure –enable-xdebug –with-php-config=/usr/local/php/bin/php-config  //配置xdebug

5. Xdebug]# make && make install  //编译安装

在第四步中的选项 –with-php-config不能省略,如果我们省略了此选项,那么有可能会报如下错误

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure: error: Cannot find php-config. Please use --with-php-config=PATH

按照上述步骤安装,如果没有什么特殊情况的话安装会顺利的进行,最后出现如下结果表示安装成功

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/

+----------------------------------------------------------------------+

|                                                                      |

|   INSTALLATION INSTRUCTIONS                                          |

|   =========================                                          |

|                                                                      |

|   See http://xdebug.org/install.php#configure-php for instructions   |

|   on how to enable Xdebug for PHP.                                   |

|                                                                      |

|   Documentation is available online as well:                         |

|   - A list of all settings:  http://xdebug.org/docs-settings.php     |

|   - A list of all functions: http://xdebug.org/docs-functions.php    |

|   - Profiling instructions:  http://xdebug.org/docs-profiling2.php   |

|   - Remote debugging:        http://xdebug.org/docs-debugger.php     |

|                                                                      |

|                                                                      |

|   NOTE: Please disregard the message                                 |

|       You should add "extension=xdebug.so" to php.ini                |

|   that is emitted by the PECL installer. This does not work for      |

|   Xdebug.                                                            |

|                                                                      |

+----------------------------------------------------------------------+

配置PHP 使其支持xdebug

按照上述最后的显示结果,说明xdebug已经安装成功,并且我们需要对php.ini文件进行配置,打开php.ini文件

# vim /usr/local/php/etc/php.ini   //打开php.ini文件

在文件中添加如下几行

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so

[Xdebug]

xdebug.remote_enable = 1   //开启远程调试

xdebug.remote_host = 192.168.18.228 //远程ip地址抑或是本机地址

xdebug.remote_port = 9000  //远程IDE服务器监听端口

xdebug.remote_handler=DBGP  //使用的协议

(除此之外,xdebug选项的详细解释请参考 xdebug所有设置说明

添加完以后,保存退出。如果PHP环境使用的是SAPIs方式,那我们需要重启Web服务器;如果使用的是FastCGI的方式那我们需要重启php-fpm。重启完以后,新建php脚本使用phpinfo()查看php的配置如下图

说明PHP配置xdebug成功。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值