PECLでXdebugをインストールする方法

- 環境
    - macOS Mojave バージョン 10.14.4
    - Homebrew 2.1.2
    - PHP 7.3.1 (cli)
    - PEAR Version: 1.10.7
    - Zend Engine Version: 3.3.1

# 経緯 : HomebrewでXdebugはインストールできないのでPECLでインストールすることにしました。
たいていHombrewでアプリはインストールしていたのですが、`Closed pull requests`となっていたのでPECLを使うことにしました。そもそもPHPで使うわけなのでPECLで端からやるべきだったのかもしれません。

```bash
$ brew search xdebug
No formula or cask found for "xdebug".
Closed pull requests:
xdebug-osx: delete (https://github.com/Homebrew/homebrew-php/pull/4837)
php72-xdebug 2.6.0RC2 (https://github.com/Homebrew/homebrew-php/pull/4726)
php7{0-2}-xdebug 2.6.0 (https://github.com/Homebrew/homebrew-php/pull/4738)
php72-xdebug 2.6.0-beta1 (https://github.com/Homebrew/homebrew-php/pull/4683)
php7{0,1}-xdebug 2.6.0beta1 (devel) (https://github.com/Homebrew/homebrew-php/pull/4686)
php72-xdebug (new formula, head only) (https://github.com/Homebrew/homebrew-php/pull/4439)
php71: migrate to homebrew/core (https://github.com/Homebrew/homebrew-php/pull/4798)
Adds debug options for php70-xdebug (GH-4338) (https://github.com/Homebrew/homebrew-php/pull/4341)
Updated xdebug-osx to v1.3 (https://github.com/Homebrew/homebrew-php/pull/4307)
Add formula for infection (https://github.com/Homebrew/homebrew-php/pull/4519)
xdebug 2.5.5 (https://github.com/Homebrew/homebrew-php/pull/4294)
enchant 2.2.0 (https://github.com/Homebrew/homebrew-core/pull/21807)
xdebug 2.5.4 (https://github.com/Homebrew/homebrew-php/pull/4162)
xdebug 2.5.3 (https://github.com/Homebrew/homebrew-php/pull/4122)
xdebug 2.5.2 (https://github.com/Homebrew/homebrew-php/pull/4120)
php70 7.0.17 (https://github.com/Homebrew/homebrew-php/pull/4044)
php{55-71} xdebug 2.5.1 (https://github.com/Homebrew/homebrew-php/pull/4013)
Add PHP 7.2.0-alpha.1 core formula (php72) (https://github.com/Homebrew/homebrew-php/pull/4211)
php{55-71}-xdebug 2.5.0 (https://github.com/Homebrew/homebrew-php/pull/3809)
php71-xdebug 2.5.0RC1 - Fixes Segfault in code coverage issue (https://github.com/Homebrew/homebrew-php/pull/3788)
```

# PECLでXdebugをインストールする
## (しなくてもいいけど)PECLの設定を確認しておく
[pecl がどこにインストールするか、何処を使うか設定を確認しておけば迷わない。](http://takuya-1st.hatenablog.jp/entry/2016/05/02/153440)というのを読んで、確かになっと思ったので確認する。

```bash
$ pecl config-show
Configuration (channel pecl.php.net):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pecl.php.net
# 省略
PEAR executables directory     bin_dir          /usr/local/opt/php/bin
# 省略
directory
PEAR data directory            data_dir         /usr/local/share/pear/data
PEAR Installer download        download_dir     /private/tmp/pear/download
# 省略
php.ini location               php_ini          /usr/local/etc/php/7.3/php.ini
# 省略
```

## Xdebugのパッケージを検索する
```bash
$ pecl search xdebug
Retrieving data...0%
Matched packages, channel pecl.php.net:
=======================================
Package Stable/(Latest) Local
xdebug  2.7.2 (stable)        Provides functions for function traces and profiling
mananoMacBookAir:~ mana$ 
```

## インストールする
```bash
$ pecl install xdebug
downloading xdebug-2.7.2.tgz ...
Starting to download xdebug-2.7.2.tgz (230,987 bytes)
.................................................done: 230,987 bytes
69 source files, building
running: phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
building in /private/tmp/pear/temp/pear-build-manaKw0tdS/xdebug-2.7.2
running: /private/tmp/pear/temp/xdebug/configure --with-php-config=/usr/local/opt/php/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
# 省略
----------------------------------------------------------------------
Libraries have been installed in:
   /private/tmp/pear/temp/pear-build-manaKw0tdS/xdebug-2.7.2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don`t forget to run 'make test'.

running: make INSTALL_ROOT="/private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2" install
Installing shared extensions:     /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.1/pecl/20180731/

  +----------------------------------------------------------------------+
  |                                                                      |
  |   INSTALLATION INSTRUCTIONS                                          |
  |   =========================                                          |
  |                                                                      |
  |   See https://xdebug.org/install.php#configure-php for instructions  |
  |   on how to enable Xdebug for PHP.                                   |
  |                                                                      |
  |   Documentation is available online as well:                         |
  |   - A list of all settings:  https://xdebug.org/docs-settings.php    |
  |   - A list of all functions: https://xdebug.org/docs-functions.php   |
  |   - Profiling instructions:  https://xdebug.org/docs-profiling2.php  |
  |   - Remote debugging:        https://xdebug.org/docs-debugger.php    |
  |                                                                      |
  |                                                                      |
  |   NOTE: Please disregard the message                                 |
  |       You should add "extension=xdebug.so" to php.ini                |
  |   that is emitted by the PECL installer. This does not work for      |
  |   Xdebug.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+


running: find "/private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2" | xargs ls -dils
8606689103   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2
8606689669   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr
8606689670   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local
8606689671   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar
8606689672   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php
8606689673   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.1
8606689674   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.1/pecl
8606689675   0 drwxr-xr-x  3 mana  wheel      96  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.1/pecl/20180731
8606689676 576 -rwxr-xr-x  1 mana  wheel  293976  5  7 22:38 /private/tmp/pear/temp/pear-build-manaKw0tdS/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.1/pecl/20180731/xdebug.so

Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.1/pecl/20180731/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.7.2
Extension xdebug enabled in php.ini
```

# インストールされたか確認する
```bash
$ php -m
[PHP Modules]
# 省略
[Zend Modules]
Xdebug
Zend OPcache

$ php --version
PHP 7.3.1 (cli) (built: Jan 10 2019 13:15:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies
```

> -m  --modules
> 例1 PHP に組み込まれた (そしてロードされた) Zend モジュールの表示
> [PHP: オプション - Manual](https://www.php.net/manual/ja/features.commandline.options.php)

# php.iniの先頭に自動でExtensionが追記されたのを確認する
記載場所を変更したり設定を追加する。

```ini:php.ini
zend_extension="xdebug.so"
[PHP]

;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
```