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

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括銀川網(wǎng)站建設(shè)、銀川網(wǎng)站制作、銀川網(wǎng)頁制作以及銀川網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,銀川網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到銀川省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
Apple在發(fā)布macOS High Sierra后,系統(tǒng)也終于自帶了php v7.1,相比于之前,如果想使用php7,還得額外想辦法( Homebrew 或者 php-osx )而言著實(shí)方便了不少。
但是,系統(tǒng)自帶的PHP只有基礎(chǔ)的配置,如果想做PHP開發(fā),Xdebug還是必須的,以下就總結(jié)一下如何在macOS High Sierra中為系統(tǒng)自帶的PHP增加Xdebug模塊?!就扑]:PHP7教程】
基礎(chǔ)環(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,所以在選擇的時(shí)候,需要選擇php71-xdebug這個(gè)安裝包。
另外由于brew中的php71-xdebug依賴于php71的,所以建議加上--without-homebrew-php這個(gè)參數(shù),這樣的話brew就會(huì)忽略安裝php71。
brew install php71-xdebug --without-homebrew-php
不過這個(gè)時(shí)候,或許你會(huì)碰到下面這樣的報(bào)錯(cuò):
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:
提示缺失依賴,從而導(dǎo)致phpize無法正常工作,phpize是用來準(zhǔn)備 PHP 擴(kuò)展庫的編譯環(huán)境的,理論上系統(tǒng)自帶的PHP應(yīng)該是有phpize的,但是沒有在/usr/include/php/*里面找到它需要的模塊,并且檢索/usr/include時(shí)發(fā)現(xiàn)這個(gè)目錄根本不存在。
Google了一圈,解決問題,就需要在/usr/include中補(bǔ)全相關(guān)的內(nèi)容,在OSX v10.10以前系統(tǒng),需要手動(dòng)做軟鏈來解決:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /usr/include
但是v10.11以后的系統(tǒng)重寫了安全策略,所以會(huì)遇到權(quán)限問題(sudo也不行):
ln: /usr/include: Operation not permitted
不過好在Apple為開發(fā)人員準(zhǔn)備了Xcode,這是一個(gè)很強(qiáng)大的工具,但是體積也很大(下載安裝有點(diǎn)慢),而一般我們只需要它提供的Command Line Tools就夠了,上面的問題,其實(shí)只要安裝Command Line Tools就可以解決:
xcode-select --install
接下來,跟著提示做,安裝、同意協(xié)議...
等待安裝結(jié)束以后,再用 brew 來安裝 php71-xdebug:
brew install php71-xdebug --without-homebrew-php
一切結(jié)束以后,brew會(huì)給出提示:
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配置文件中不一定有,因此需要手動(dòng)添加Xdebug的配置項(xiàng):
[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:
# 關(guān)閉php-fpm sudo killall php-fpm # 啟動(dòng)php-fpm sudo php-fpm
運(yùn)行php -i "(command-line 'phpinfo()')" | grep xdebug后,你就可以看到關(guān)于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ā)工具之一,雖然輕量,但是對(duì)標(biāo)各類IDE毫不遜色,微軟良心之作,通過安裝不同的插件可以擴(kuò)展它的能力,其中有一款 PHP Debug 的插件,可以作為Xdebug的橋梁,方便直接通過Xdebug調(diào)試PHP,官方的描述十分貼切:
官網(wǎng)的指導(dǎo)也寫的相當(dāng)不錯(cuò):
這里需要注意的是它推薦開啟Xdebug配置項(xiàng)中的remote_autostart這一項(xiàng)。
新聞名稱:macOSPHP7如何增加Xdebug
瀏覽地址:http://m.5511xx.com/article/cddedgg.html


咨詢
建站咨詢
