欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

macOSPHP7怎么增加Xdebug

本篇內(nèi)容主要講解“macOS PHP7怎么增加Xdebug”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“macOS PHP7怎么增加Xdebug”吧!

創(chuàng)新互聯(lián)擁有十多年成都網(wǎng)站建設工作經(jīng)驗,為各大企業(yè)提供網(wǎng)站設計、成都做網(wǎng)站服務,對于網(wǎng)頁設計、PC網(wǎng)站建設(電腦版網(wǎng)站建設)、app軟件開發(fā)公司、wap網(wǎng)站建設(手機版網(wǎng)站建設)、程序開發(fā)、網(wǎng)站優(yōu)化(SEO優(yōu)化)、微網(wǎng)站、域名注冊等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設行業(yè)積累了很多網(wǎng)站制作、網(wǎng)站設計、網(wǎng)絡營銷經(jīng)驗,集策劃、開發(fā)、設計、營銷、管理等網(wǎng)站化運作于一體,具備承接各種規(guī)模類型的網(wǎng)站建設項目的能力。

macOS系統(tǒng)PHP7增加Xdebug

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這個安裝包。

macOS PHP7怎么增加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é)議...
macOS PHP7怎么增加Xdebug

等待安裝結束以后,再用 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,官方的描述十分貼切:

PHP Debug Adapter for Visual Studio Code

官網(wǎng)的指導也寫的相當不錯:

  1. Install XDebug
    I highly recommend you make a simple test.php file, put a phpinfo(); 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.

  2. 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 your phpinfo() output under "Loaded Configuration File".

  3. Enable remote debugging in your php.ini:

    [XDebug]
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1

    There are other ways to tell XDebug to connect to a remote debugger than remote_autostart, like cookies, query parameters or browser extensions. I recommend remote_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.

  4. If you are doing web development, don't forget to restart your webserver to reload the settings

  5. Verify your installation by checking your phpinfo() output for an XDebug section.

這里需要注意的是它推薦開啟Xdebug配置項中的remote_autostart這一項。

好了,經(jīng)過上面的操作,你應該可以跟Demo里面一樣在VSCode中調(diào)試PHP了。
macOS PHP7怎么增加Xdebug

到此,相信大家對“macOS PHP7怎么增加Xdebug”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!

網(wǎng)頁名稱:macOSPHP7怎么增加Xdebug
網(wǎng)頁網(wǎng)址:http://www.chinadenli.net/article40/ishhho.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航商城網(wǎng)站Google微信小程序動態(tài)網(wǎng)站定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設計