Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况。在日常开发中,我们会使用如 print_r() var_dump()等函数来进行调试,但毕竟Xdebug更加的专业,简单介绍下在Ubuntu-14.04下Xdebug-2.2.5的安装。

phpha@asus:~$ wget http://www.xdebug.org/files/xdebug-2.2.5.tgz
phpha@asus:~$ tar -zxf xdebug-2.2.5.tgz
phpha@asus:~$ cd xdebug-2.2.5/
phpha@asus:~/xdebug-2.2.5$ /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
phpha@asus:~/xdebug-2.2.5$ ./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
phpha@asus:~/xdebug-2.2.5$ sudo make
phpha@asus:~/xdebug-2.2.5$ sudo make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-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.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+

以上已经成功安装了Xdebug扩展,接下来还需要我们对php.ini配置文件就行一些修改。

phpha@asus:~$ sudo vim /usr/local/php/etc/php.ini
# 添加以下配置选项,更多配置选项请自己借助查看官方说明
[Xdebug]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20121212/xdebug.so
xdebug.auto_trace = on
xdebug.default_enable = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.trace_output_dir = "/usr/local/php/xdebug/"
xdebug.profiler_output_dir = "/usr/local/php/xdebug/"
# 重启Apache
phpha@asus:~$ sudo service apache restart

现在就可以在phpinfo()里看到Xdebug的相关信息了,到此结束。

标签:ubuntu / xdebug