Linux下用Xdebug調試php 博客分類: php PHPLinuxZendEclipseC# 為了調試PHP程序,安裝一下xdebug. 官方網址: http://www.xdebug.org 首先下載xdebug2.1.0,在官方首頁下載源代碼,下載回來的文件名是:xdebug-2.1.0.tgz xdebug的版本需與您的php版本相對應,由於偶的php是5.3.2,所以下載xdebug2.1.0 Xml代碼 收藏代碼 cd /your/download/path tar zxvf xdebug-2.1.0.tgz cd xdebug-2.1.0 運行phpize Xml代碼 收藏代碼 phpize 如果沒有將phpize加入$PATH,則應該使用全路徑 這里不需要--prefix,編譯好之后直接把modules里的xdebug.so文件復制走即可。 Xml代碼 收藏代碼 ./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config Xml代碼 收藏代碼 make 把xdebug.so復制到了php安裝目錄,裝php的時候指定了安裝目錄,所以復制到/usr/local/php/xdebug里。隨便你復制到哪都行,只要你清楚知道。。。需要改下面一條命令的路徑為你自己的。 Xml代碼 收藏代碼 cp modules/xdebug.so /usr/local/php/xdebug 把下面這行添加到php.ini文件的最后。如果您定義過php.ini的存放位置,一定要找到位置哦,建議弄個phpinfo(),查看到php.ini文件的具體位置。我的位置是在:/usr/local/etc/php.ini 添加下面內容: Xml代碼 收藏代碼 [Xdebug] zend_extension ="/usr/local/php5/xdebug/xdebug.so" xdebug.profiler_enable=on xdebug.trace_output_dir="/usr/local/php5/xdebug/" xdebug.profiler_output_dir="/usr/local/php5/xdebug/" xdebug.remote_enable=on xdebug.remote_handler=dbgp ;xdebug.remote_host=localhost xdebug.remote_port=9999 注意,如果您安裝過zend optimizer 那么,注意您的php.ini文件中是否已存在zend_extension= ,如果已經存在,請注釋掉,在zend_extension=前加上; ,示例: ;zend_extension="/usr/local/lib/php/20060613/ZendExtensionManager.so" 這樣,才可以正常安裝運行好xdebug. 重啟你的web服務器。 接下來打開phpinfo(),看看里面是否有xdebug的信息了。 This program makes use of the Zend Scripting Language Engine: Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Xdebug v2.0.2, Copyright (c) 2002-2007, by Derick Rethans 可能遇到的問題 1.Cannot find autoconf /usr/local/php/bin/phpize 提示 Xml代碼 收藏代碼 Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable is set correctly and then rerun this script. 源代碼目錄下也沒有生成configure 需安裝兩個軟件包 Xml代碼 收藏代碼 imake-1.0.2-3.i386.rpm autoconf-2.59-12.noarch.rpm 2.configure: error: Cannot find php-config Xml代碼 收藏代碼 ./configure --with-php-config=/usr/local/php/bin/php-config # 這里如果直接執行./configure很有可能會報錯 # "configure: error: Cannot find php-config. Please use --with-php-config=PATH", # 你的配置文件位置可能不在這個目錄,這個文件通常是在php安裝目錄的bin目錄下的一個文件名叫做php-config或者php-config5的文件,實在找不到就find一下咯