今天有個PHP小生問我php 的Xdebug擴充的問題,於是就又重新寫了這篇筆記,其實這個安裝配置很簡單,考慮到新手的理解,配備圖文較為詳細和實際類比操作步驟,大牛略過即可
首先開啟linux終端執行命令 git clone git://github.com/xdebug/xdebug.git 下載xdebug擴充包,如: (沒有git的請先安裝git)
然後執行如下命令切換到xdebug檔案包目錄
[Happy@localhost www]$ cd xdebug
在xdebug目錄下執行phpize命令(具體替換成您的實際PHP安裝路徑下的phpize檔案所在路徑)
[Happy@localhost xdebug]$ /usr/local/php/bin/phpize (執行結果如可看到php的版本日期等)
編譯xdebug擴充包
[Happy@localhost xdebug]$ ./configure --with-php-config=/usr/local/php/bin/php-config
[Happy@localhost xdebug]$ make (出現如下資訊則說明make成功)
然後執行最後一步make install完成安裝
[Happy@localhost xdebug]$ make install
出現表示安裝成功並顯示出php擴充所在目錄位置
此時查看擴充目錄即可看到xdebug.so擴充檔案已經安裝到PHP擴充目錄下
配置PHP.INI 檔案 加入XDEBUG擴充
[Xdebug]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable = true
xdebug.remote_host = localhost
#default port 9000
#xdebug.remote_port = 9000
xdebug.profiler_enable = on
xdebug.trace_output_dir = "/var/www/phpxdebug"
xdebug.profiler_output_dir = "/var/www/phpxdebug"
xdebug.auto_trace = On
xdebug.show_exception_trace = On
xdebug.remote_autostart = On
xdebug.collect_vars = On
xdebug.collect_return = On
xdebug.remote_handler =dbgp
xdebug.max_nesting_level = 10000
php.ini配置參數修改完成後在PHP頁面中調用phpinfo()函數可看到頁面中Xdebug的擴充資訊和相關參數選項,我這裡的設定:
php xdebug 參數說明(更多問題請參見 摘取天上星 之前關於xdebug的日誌)
zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so" #載入擴充檔案xdebug.remote_enable = truexdebug.remote_host = localhost#xdebug.remote_port = 9000 #預設連接埠 9000xdebug.profiler_enable = onxdebug.trace_output_dir = "/var/www/phpxdebug"xdebug.profiler_output_dir = "/var/www/phpxdebug"#其餘參數#開啟自動跟蹤xdebug.auto_trace = On#開啟異常跟蹤xdebug.show_exception_trace = On#開啟遠端偵錯自動啟動xdebug.remote_autostart = On#收集變數xdebug.collect_vars = On#收集傳回值xdebug.collect_return = On#用於zend studio遠端偵錯的應用程式層通訊協定xdebug.remote_handler =dbgp#如果設得太小,函數中有遞迴調用自身次數太多時會報超過最大嵌套數錯xdebug.max_nesting_level = 10000zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"Xdebug載入方法,不同系統及 PHP 版本有不同寫法Linux 和 Mac OS X : zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
Windows Thread-Safe 版 PHP : zend_extension_ts = "D:\php\ext\xdebug.dll"Windows Non-Thread-Safe 版 PHP : zend_extension = "D:\php\ext\xdebug.dll"所以同一伺服器只能載入一個調試工具,要麼 Zend Debugger 要麼 Xdebug但在 PHP5.5 環境下測試, Thread-Safe 版 PHP 後面不能加 _ts 只能寫成 zend_extension = xdebug.remote_enable = true 允許遠程IDE調試xdebug.profiler_enable = on 及後面的目錄 "/var/www/phpxdebug" 作用是開啟把執行情況的分析檔案寫入到指定目錄中的功能,可自由設定。也可不寫產生的檔案,例如 cachegrind.out.4408 這種格式命名的檔案,用編輯器開啟可以看到很多程式啟動並執行相關細節資訊
以上就介紹了php xdebug的編譯安裝以及配置說明,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。