MacのPHP5をPHP7にbrewでアップデートする

# Macに入ってるPHP5をPHP7にアップデートする
作業メモです

### 初期状態
OS: OS X EL Capitan(10.11.6)

```
$ php -v
PHP 5.5.38 (cli) (built: Aug 21 2016 21:48:49)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
```
### Homebrew
ここを参考にさせてもらいました。
[MacにHomebrewをインストールする](http://qiita.com/is0me/items/475fdbc4d770534f9ef1)

### HomebrewでPHP7を検索
`brew search php@7`で検索

```
$ brew search php@7
==> Searching local taps...
php@7.0                    php@7.1                    php@7.2
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
...
```

### PHP7をインストール
`brew install php@7.1` でインストール

```
$ brew install php@7.1
==> Downloading https://homebrew.bintray.com/bottles/php@7.1-7.1.16_1.sierra.bottle.tar.gz
Already downloaded: /Users/$USER/Library/Caches/Homebrew/php@7.1-7.1.16_1.sierra.bottle.tar.gz
==> Pouring php@7.1-7.1.16_1.sierra.bottle.tar.gz
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_ini /usr/local/etc/php/7.1/php.ini system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_dir /usr/local/share/pear@7.1 system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set doc_dir /usr/local/share/pear@7.1/doc system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20160303 system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set bin_dir /usr/local/opt/php@7.1/bin system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set data_dir /usr/local/share/pear@7.1/data system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set cfg_dir /usr/local/share/pear@7.1/cfg system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set www_dir /usr/local/share/pear@7.1/htdocs system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set test_dir /usr/local/share/pear@7.1/test system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_bin /usr/local/opt/php@7.1/bin/php system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so

    <FilesMatch .php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.1/

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/php@7.1/lib
    CPPFLAGS: -I/usr/local/opt/php@7.1/include


To have launchd start php@7.1 now and restart at login:
  brew services start php@7.1
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php@7.1/7.1.16_1: 514 files, 67MB
```

### Path通す
.bash_profileに追加。

```
export PATH="/usr/local/opt/php@7.1/bin:$PATH"
export PATH="/usr/local/opt/php@7.1/sbin:$PATH"
```

### 確認
```
$ php -v
PHP 7.1.16 (cli) (built: Apr 12 2018 03:25:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies
```

とても簡単。(^ω^)