Linux下用Xdebug調試php

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一下咯
相關文章
相關標籤/搜索