新聞中心
macOS系統(tǒng)php7增加Xdebug

成都創(chuàng)新互聯(lián)服務項目包括銀川網(wǎng)站建設、銀川網(wǎng)站制作、銀川網(wǎng)頁制作以及銀川網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,銀川網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到銀川省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
Apple在發(fā)布macOS High Sierra后,系統(tǒng)也終于自帶了php v7.1,相比于之前,如果想使用php7,還得額外想辦法( Homebrew 或者 php-osx )而言著實方便了不少。
但是,系統(tǒng)自帶的PHP只有基礎的配置,如果想做PHP開發(fā),Xdebug還是必須的,以下就總結一下如何在macOS High Sierra中為系統(tǒng)自帶的PHP增加Xdebug模塊?!就扑]:PHP7教程】
基礎環(huán)境( macOS 及 PHP 信息)
- macOS High Sierra: v10.13.3
- PHP: v7.1.7
安裝Xdebug
Xdebug官網(wǎng)安裝文檔中有MAC推薦的方式,鑒于系統(tǒng)自帶的是PHP是v7.1.7,所以在選擇的時候,需要選擇php71-xdebug這個安裝包。
另外由于brew中的php71-xdebug依賴于php71的,所以建議加上--without-homebrew-php這個參數(shù),這樣的話brew就會忽略安裝php71。
brew install php71-xdebug --without-homebrew-php
不過這個時候,或許你會碰到下面這樣的報錯:
phpize grep: /usr/include/php/main/php.h: No such file or directory grep: /usr/include/php/Zend/zend_modules.h: No such file or directory grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory Configuring for: PHP Api Version: Zend Module Api No: Zend Extension Api No:
提示缺失依賴,從而導致phpize無法正常工作,phpize是用來準備 PHP 擴展庫的編譯環(huán)境的,理論上系統(tǒng)自帶的PHP應該是有phpize的,但是沒有在/usr/include/php/*里面找到它需要的模塊,并且檢索/usr/include時發(fā)現(xiàn)這個目錄根本不存在。
Google了一圈,解決問題,就需要在/usr/include中補全相關的內(nèi)容,在OSX v10.10以前系統(tǒng),需要手動做軟鏈來解決:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /usr/include
但是v10.11以后的系統(tǒng)重寫了安全策略,所以會遇到權限問題(sudo也不行):
ln: /usr/include: Operation not permitted
不過好在Apple為開發(fā)人員準備了Xcode,這是一個很強大的工具,但是體積也很大(下載安裝有點慢),而一般我們只需要它提供的Command Line Tools就夠了,上面的問題,其實只要安裝Command Line Tools就可以解決:
xcode-select --install
接下來,跟著提示做,安裝、同意協(xié)議...
等待安裝結束以后,再用 brew 來安裝 php71-xdebug:
brew install php71-xdebug --without-homebrew-php
一切結束以后,brew會給出提示:
To finish installing xdebug for PHP 7.1:
* /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the xdebug module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the xdebug module.
* - If you see it, you have been successful!
開啟PHP的Xdebug
經(jīng)過上面步驟,系統(tǒng)里面是有Xdebug了,但是在php.ini配置文件中不一定有,因此需要手動添加Xdebug的配置項:
[xdebug] zend_extension="/usr/local/opt/php71-xdebug/xdebug.so" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_connect_back = 1 xdebug.remote_port = 9000 xdebug.scream = 0 xdebug.show_local_vars = 1
然后就是重啟php-fpm:
# 關閉php-fpm sudo killall php-fpm # 啟動php-fpm sudo php-fpm
運行php -i "(command-line 'phpinfo()')" | grep xdebug后,你就可以看到關于Xdebug的配置內(nèi)容了:
xdebug ... xdebug.remote_autostart => On => On xdebug.remote_connect_back => On => On xdebug.remote_cookie_expire_time => 3600 => 3600 xdebug.remote_enable => On => On xdebug.remote_handler => dbgp => dbgp xdebug.remote_host => localhost => localhost xdebug.remote_log => no value => no value xdebug.remote_mode => req => req xdebug.remote_port => 9000 => 9000 xdebug.remote_timeout => 200 => 200 xdebug.scream => Off => Off ...
Visual Studio Code - PHP Debug
VSCode是目前最流行的開發(fā)工具之一,雖然輕量,但是對標各類IDE毫不遜色,微軟良心之作,通過安裝不同的插件可以擴展它的能力,其中有一款 PHP Debug 的插件,可以作為Xdebug的橋梁,方便直接通過Xdebug調(diào)試PHP,官方的描述十分貼切:
官網(wǎng)的指導也寫的相當不錯:
這里需要注意的是它推薦開啟Xdebug配置項中的remote_autostart這一項。
分享題目:macOSPHP7如何增加Xdebug
URL分享:http://m.fisionsoft.com.cn/article/cddedgg.html


咨詢
建站咨詢
