xdebugインストール(mac)

phpunitでカバレッジを出力したいのでxdebugをインストールします。

インストール

参考元
https://xdebug.org/docs/install

pecl install xdebug

公式の手順によるとmacの場合、上記のコマンドでインストールするみたいです。

ただ、自分の環境ではpeclコマンドが実行できなかったので、先にこちらをインストールしておきます。

pearインストール

参考元
https://qiita.com/NakanishiTetsuhiro/items/19012ca88ce501a6f6a4

上記によるとpearをインストールすれば一緒にpeclも使えるらしいです。
こちらを参考にインストールします。

コマンド

curl -O https://pear.php.net/go-pear.phar 
php -d detect_unicode=0 go-pear.phar 
sudo php /usr/lib/php/ install-pear-nozlib.phar

実行

$ curl -O https://pear.php.net/go-pear.phar
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100 3532k  100 3532k    0     0   288k      0  0:00:12  0:00:12 --:--:--  567k
$ ls
 go-pear.phar
$
$ php -d detect_unicode=0 go-pear.phar

…(略)…

For more information about PEAR, see:
 http://pear.php.net/faq.php
   http://pear.php.net/manual/
 Thanks for using go-pear!
$
$ sudo php /usr/lib/php/ install-pear-nozlib.phar
 Password:
 No log handling enabled - using stderr logging
 Created directory: /var/db/net-snmp
 Created directory: /var/db/net-snmp/mib_indexes
$

OK。インストールされたことを確認しておきます。

pearコマンド。

$ $HOME/pear/bin/pear -V
 PEAR Version: 1.10.10
 PHP Version: 7.1.23
 Zend Engine Version: 3.1.0
 Running on: Darwin xxxxxx 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
$

OK。続いてpeclコマンド。

$ $HOME/pear/bin/pecl -V
 PEAR Version: 1.10.10
 PHP Version: 7.1.23
 Zend Engine Version: 3.1.0
 Running on: Darwin xxxxxxxxx 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
$

OK。無事にインストールされたようなので、パスも通しておきます。

export PATH=$PATH:$HOME/pear/bin/

phpインストール

とりあえず、実行してみます。

$ pecl install xdebug
 WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
 downloading xdebug-2.9.0.tgz …
 Starting to download xdebug-2.9.0.tgz (242,853 bytes)
 …………………………………………..done: 242,853 bytes
 90 source files, building
 running: 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:
 Cannot find autoconf. Please check your autoconf installation and the
 $PHP_AUTOCONF environment variable. Then, rerun this script.
 ERROR: `phpize' failed
$

失敗しました。

pearのインストールの参考にしたサイトではSIPを一時的にオフにするという手順になっているので、それで解決するかもしれないですが、今回は別の方法にします。

phpがmacのビルドインのものなので、phpを改めてインストールする形です。

コマンド

参考元
https://qiita.com/74th/items/634dfee949b7ad5988c2

brew install php@7.2

実行

先にbrew自体をアップデート。

$ brew update
 Already up-to-date.
$

OK。続いて、phpのインストール。

$ brew install php@7.2
 Updating Homebrew…
…
To have launchd start php@7.2 now and restart at login:
   brew services start php@7.2
 Or, if you don't want/need a background service you can just run:
   php-fpm
$

なんか、他にも色々とインストールされました。参考にしたサイトがHomebrewでのインストールにしていたのでそうしましたが、他の方法の方が良かったかもしれないです。

とりあえず、インストールはできた模様。

$  /usr/local/opt/php\@7.2/bin/php -v
 PHP 7.2.26 (cli) (built: Dec 18 2019 15:28:58) ( NTS )
 Copyright (c) 1997-2018 The PHP Group
 Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
     with Zend OPcache v7.2.26, Copyright (c) 1999-2018, by Zend Technologies
$

最後に「brew install」の際に表示されたコマンドも実行して、パスを通すなども実施しておきます。

$ export PATH="/usr/local/opt/php@7.2/bin:$PATH"
$ export PATH="/usr/local/opt/php@7.2/sbin:$PATH"
$ export LDFLAGS="-L/usr/local/opt/php@7.2/lib"
$ export CPPFLAGS="-I/usr/local/opt/php@7.2/include"

xdebugインストール

コマンド

pecl install xdebug

実行

$ pecl install xdebug
 WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
 downloading xdebug-2.9.0.tgz …
 Starting to download xdebug-2.9.0.tgz (242,853 bytes)

…

Build process completed successfully
 Installing '/usr/local/Cellar/php@7.2/7.2.26/pecl/20170718/xdebug.so'
 install ok: channel://pecl.php.net/xdebug-2.9.0
 Extension xdebug enabled in php.ini
$

今度は成功しました。

phpunitを実行し無事にカバレッジが出力されたことを確認できOKです。

コメント

タイトルとURLをコピーしました