安装Xdebug

发布人:kimi  时间:2007-10-29 21:45  来源: 网络转载  查看: 1045次   TAG: Xdebug安装  Xdebug教程 



Windows下安装Xdebug


以PHP5.1.4,Windows平台为例(其它PHP版本,其它平台请参看官网文档):
1. 登录www.xdebug.org,在首页右侧有一个Windows modules,选择其中的PHP5.1.2+,下载php_xdebug-5.1.2-2.0.0beta6.dll文件;
2. 将下载的php_xdebug-5.1.2-2.0.0beta6.dll放到C:\php5\ext目录,重命名为php_xdebug.dll;
3. 编辑php.ini,加入下面几行:
 extension=php_xdebug.dll
 [Xdebug]
 xdebug.profiler_enable=on
 xdebug.trace_output_dir="I:\Projects\xdebug"
 xdebug.profiler_output_dir="I:\Projects\xdebug" 后面的目录“I:\Projects\xdebug”为你想要放置Xdebug输出的数据文件的目录,可自由设置。
4. 重启Apache;
5. 写一个test.php,内容为<?php phpinfo(); ?>,如果输出的内容中有看到xdebug,说明安装配置成功。


在windows下安装xdebug



在linux下安装Xdebug



Xdebug 可以很轻松地从 UNIX® 类操作系统(包括 Mac OS X)中的源代码构建。如果是在 Microsoft® Windows® 上使用 PHP,则可以从 Xdebug Web 站点下载最新 PHP 版本的二进制 Xdebug 模块。


让我们来构建和安装适用于 Debian “Sarge” Linux® 和 PHP V4.3.10-19 的 Xdebug。在撰写本文时,Xdebug 的最新版本是 V2.0.0RC4,发布于 2007 年 5 月 17 日。要继续本文,必须拥有 phpize 和 php-config 实用程序,并且必须能够编辑系统的 php.ini 配置文件(如果没有实用程序,请访问 PHP.net 以获得如何从头构建 PHP 的源代码和说明)。请执行以下步骤:



  1. 下载 Xdebug tarball(一个用 gzip 压缩的 .tar 归档文件)。wget 命令可以帮助您轻松地完成此操作:



     $ 
    wget http://www.xdebug.org/files/xdebug-2.0.0RC4.tgz
                        


  2. 解压缩该 tarball 并切换到源代码目录:



    $ tar xzf xdebug-2.0.0RC4.tgz
    $ cd xdebug-2.0.0RC4
                        


  3. 运行 phpize 以准备适用于您的 PHP 版本的 Xdebug 代码:



    $ phpize
    Configuring for:
    PHP Api Version:         20020918
    Zend Module Api No:      20020429
    Zend Extension Api No:   20021010

    phpize 的输出是一个脚本 —— 通常名为配置 —— 用于调整其余的构建过程。

  4. 运行配置脚本:



    $ ./configure
    checking build system type... i686-pc-linux-gnu
    checking host system type... i686-pc-linux-gnu
    checking for gcc... gcc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables...
    checking for suffix of object files... o
    ...
    checking whether stripping libraries is possible... yes
    appending configuration tag "F77" to libtool
    configure: creating ./config.status
    config.status: creating config.h


  5. 通过运行 make 构建 Xdebug 扩展:



    $ make
    /bin/sh /home/strike/tmp/xdebug-2.0.0RC4/libtool
    --mode=compile gcc  -I.
    -I/home/strike/tmp/xdebug-2.0.0RC4 -DPHP_ATOM_INC
    -I/home/strike/tmp/xdebug-2.0.0RC4/include
    -I/home/strike/tmp/xdebug-2.0.0RC4/main
    -I/home/strike/tmp/xdebug-2.0.0RC4
    -I/usr/include/php4 -I/usr/include/php4/main
    -I/usr/include/php4/Zend -I/usr/include/php4/TSRM
    -DHAVE_CONFIG_H  -g -O0 -c
    /home/strike/tmp/xdebug-2.0.0RC4/xdebug.c -o
    xdebug.lo mkdir .libs
    ...
    Build complete.
    (It is safe to ignore warnings about tempnam and tmpnam).

    使用 make 将生成 Xdebug 扩展 xdebug.so。

  6. 安装该扩展:



    $ sudo make install
    Installing shared extensions:     /usr/lib/php4/20020429/

    继续之前,使用鼠标选择并复制上一条命令显示的目录。该路径对于最后一步配置扩展至关重要。

  7. 在您喜欢的文本编辑器中打开 php.ini 文件,然后添加以下代码:



    zend_extension = /usr/lib/php4/20020429/xdebug.so
    xdebug.profiler_enable = Off
    xdebug.default_enable = On

    第一行将装入 Xdebug 扩展;第二行将禁用 Xdebug 的分析器功能(只是为了简单起见),而第三行将启用扩展的调试功能。

要检验 Xdebug 扩展是否已经安装并启用,请重新启动 Web 服务器,然后用代码 <?php phpinfo(); ?> 创建简单的一行 PHP 应用程序。如果将浏览器指向文件 —— 如 http://localhost/phpinfo.php —— 并向下滚动,您应当会看到类似图 1 所示的内容。


图 1. 检验 Xdebug 扩展是否已经安装并运行
 在linux下安装xdebug


注:如果您在 phpinfo() 的输出中没有看到 Xdebug 部分,则 Xdebug 装入失败。Apache 错误日志会列出原因。常见错误包括 zend_extension 的路径错误或者与其他扩展发生冲突。例如,如果需要使用 XCache 和 Xdebug,一定要先装入 XCache。但是,由于 Xdebug 适于在开发时使用并假定 xdebug.so 的路径正确,因此需要禁用其他扩展并重试。然后您可以重新启用扩展以执行其他测试,如缓存的效果。Xdebug 站点还有其他一些故障检修技巧。

相关阅读

本月热门