您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“macOS PHP7怎么增加Xdebug”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“macOS PHP7怎么增加Xdebug”吧!
macOS系統(tǒng)PHP7增加Xdebug
Apple在發(fā)布macOS High Sierra后,系統(tǒng)也終于自帶了php v7.1,相比于之前,如果想使用php7,還得額外想辦法( Homebrew 或者 php-osx )而言著實方便了不少。
但是,系統(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,所以在選擇的時候,需要選擇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:
提示缺失依賴,從而導(dǎo)致phpize
無法正常工作,phpize
是用來準備 PHP 擴展庫的編譯環(huán)境的,理論上系統(tǒng)自帶的PHP應(yīng)該是有phpize
的,但是沒有在/usr/include/php/*
里面找到它需要的模塊,并且檢索/usr/include
時發(fā)現(xiàn)這個目錄根本不存在。
Google了一圈,解決問題,就需要在/usr/include
中補全相關(guān)的內(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)重寫了安全策略,所以會遇到權(quán)限問題(sudo
也不行):
ln: /usr/include: Operation not permitted
不過好在Apple為開發(fā)人員準備了Xcode,這是一個很強大的工具,但是體積也很大(下載安裝有點慢),而一般我們只需要它提供的Command Line Tools就夠了,上面的問題,其實只要安裝Command Line Tools就可以解決:
xcode-select --install
接下來,跟著提示做,安裝、同意協(xié)議...
等待安裝結(jié)束以后,再用 brew 來安裝 php71-xdebug:
brew install php71-xdebug --without-homebrew-php
一切結(jié)束以后,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
:
# 關(guān)閉php-fpm sudo killall php-fpm # 啟動php-fpm sudo php-fpm
運行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ā)工具之一,雖然輕量,但是對標各類IDE毫不遜色,微軟良心之作,通過安裝不同的插件可以擴展它的能力,其中有一款 PHP Debug 的插件,可以作為Xdebug的橋梁,方便直接通過Xdebug調(diào)試PHP,官方的描述十分貼切:
PHP Debug Adapter for Visual Studio Code
官網(wǎng)的指導(dǎo)也寫的相當不錯:
Install XDebug
I highly recommend you make a simpletest.php
file, put aphpinfo();
statement in there, then copy the output and paste it into the XDebug installation wizard. It will analyze it and give you tailored installation instructions for your environment.
In short:
On Windows: Download the appropiate precompiled DLL for your PHP version, architecture (64/32 Bit), thread safety (TS/NTS) and Visual Studio compiler version and place it in your PHP extension folder.
On Linux: Either download the source code as a tarball or clone it with git, then compile it.
Configure PHP to use XDebug by adding
zend_extension=path/to/xdebug
to your php.ini.
The path of your php.ini is shown in yourphpinfo()
output under "Loaded Configuration File".Enable remote debugging in your php.ini:
[XDebug] xdebug.remote_enable = 1 xdebug.remote_autostart = 1There are other ways to tell XDebug to connect to a remote debugger than
remote_autostart
, like cookies, query parameters or browser extensions. I recommendremote_autostart
because it "just works". There are also a variety of other options, like the port (by default 9000), please see the XDebug documentation on remote debugging for more information.If you are doing web development, don't forget to restart your webserver to reload the settings
Verify your installation by checking your
phpinfo()
output for an XDebug section.
這里需要注意的是它推薦開啟Xdebug配置項中的remote_autostart
這一項。
好了,經(jīng)過上面的操作,你應(yīng)該可以跟Demo里面一樣在VSCode中調(diào)試PHP了。
到此,相信大家對“macOS PHP7怎么增加Xdebug”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。