[mac][php] PHP 7.0 → 7.1へバージョンアップ

参考）
MacOSXでbrew install phpをVersion7.1へ 
http://qiita.com/bohebohechan/items/720cc0f830f3222bf99d

## ざっくり手順

もともとPHP7.0をbrewでインストール済みだったので、
今回はリポジトリ追加は行わず。

- brew update
- brew upgrade
- brew search php  ※いちおうあるか確認しておく
- brew unlink php70
- brew install php71

でインストール。

```
$ brew install php71
==> Installing php71 from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php71-7.1.6_18.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php71-7.1.6_18.yosemite.bottle.tar.gz
==> Caveats
The php.ini file can be found in:
    /usr/local/etc/php/7.1/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

      PATH="/usr/local/bin:$PATH"

PHP71 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
  export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist

The control script is located at /usr/local/opt/php71/sbin/php71-fpm

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

  PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'homebrew-php.josegonzalez.php71.plist' in old versions of this formula.

With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd24 option. See  brew options php71 for more details.

To have launchd start homebrew/php/php71 now and restart at login:
  brew services start homebrew/php/php71
==> Summary
🍺  /usr/local/Cellar/php71/7.1.6_18: 349 files, 40MB
```

ちなみにbrew search php した際にphp72もあったけど、
まだα版なので今回はインストール見送り。  

## 確認

まあ、これでインストールできてないとかそんなことはないと思うが、

```
$ php -v
PHP 7.1.6 (cli) (built: Jun 23 2017 08:41:51) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
```

はい。問題なかった。

以下のフレームワークを使った個人既存のプロジェクトで、
軽く動作確認してみましたが問題なし。  

- CodeIgniter 4dev
- CodeIgniter 2.x （フレームワークのコアは昨年PHP7.0最適化済み）

## その後

昨年PHP7.0をインストールしたあと、
php.iniをどういじったかとか、拡張モジュール何を入れたとか覚えてないので、
必要ないかもしれないけどいちおう確認する。

### php.ini差分

```
$ diff /usr/local/etc/php/7.1/php.ini /usr/local/etc/php/7.0/php.ini
146c146
< ; session.sid_bits_per_character
---
> ; session.hash_bits_per_character
160a161,165
> ; url_rewriter.tags
> ;   Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ;   Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ;   Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> 
242,258d246
< ; URL rewriter function rewrites URL on the fly by using
< ; output buffer. You can set target tags by this configuration.
< ; "form" tag is special tag. It will add hidden input tag to pass values.
< ; Refer to session.trans_sid_tags for usage.
< ; Default Value: "form="
< ; Development Value: "form="
< ; Production Value: "form="
< ;url_rewriter.tags
< 
< ; URL rewriter will not rewrites absolute URL nor form by default. To enable
< ; absolute URL rewrite, allowed hosts must be defined at RUNTIME.
< ; Refer to session.trans_sid_hosts for more details.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;url_rewriter.hosts
< 
300,303c288
< ; The value is also used for json_encode when encoding double values.
< ; If -1 is used, then dtoa mode 0 is used which automatically select the best
< ; precision.
< serialize_precision = -1
---
> serialize_precision = 17
341c326
< ;realpath_cache_size = 4096k
---
> ;realpath_cache_size = 16k
703a689
> ; mbstring or iconv output handler is used.
777,781d762
< ; if cgi.discard_path is enabled, the PHP CGI binary can safely be placed outside
< ; of the web tree and people will not be able to circumvent .htaccess security.
< ; http://php.net/cgi.dicard-path
< ;cgi.discard_path=1
< 
802,808d782
< ; cgi.check_shebang_line controls whether CGI PHP checks for line starting with #!
< ; (shebang) at the top of the running script. This line might be needed if the
< ; script support running both as stand-alone script and via PHP CGI<. PHP in CGI
< ; mode skips this line and ignores its content if this directive is turned on.
< ; http://php.net/cgi.check-shebang-line
< ;cgi.check_shebang_line=1
< 
895d868
< ;extension=php_ftp.dll
1202,1214d1174
< ; Records communication from all extensions using mysqlnd to the specified log
< ; file.
< ; http://php.net/mysqlnd.debug
< ;mysqlnd.debug =
< 
< ; Defines which queries will be logged.
< ; http://php.net/mysqlnd.log_mask
< ;mysqlnd.log_mask = 0
< 
< ; Default size of the mysqlnd memory pool, which is used by result sets.
< ; http://php.net/mysqlnd.mempool_default_size
< ;mysqlnd.mempool_default_size = 16000
< 
1224,1232d1183
< ; Timeout for network requests in seconds.
< ; http://php.net/mysqlnd.net_read_timeout
< ;mysqlnd.net_read_timeout = 31536000
< 
< ; SHA-256 Authentication Plugin related. File with the MySQL server public RSA
< ; key.
< ; http://php.net/mysqlnd.sha256_server_public_key
< ;mysqlnd.sha256_server_public_key =
< 
1451a1403,1415
> ; How many bytes to read from the file.
> ; http://php.net/session.entropy-length
> ;session.entropy_length = 32
> 
> ; Specified here to create the session id.
> ; http://php.net/session.entropy-file
> ; Defaults to /dev/urandom
> ; On systems that don't have /dev/urandom but do have /dev/arandom, this will default to /dev/arandom
> ; If neither are found at compile time, the default is no entropy file.
> ; On windows, setting the entropy_length setting will activate the
> ; Windows random source (using the CryptoAPI)
> ;session.entropy_file = /dev/urandom
> 
1473,1505c1437,1445
< ; Set session ID character length. This value could be between 22 to 256.
< ; Shorter length than default is supported only for compatibility reason.
< ; Users should use 32 or more chars.
< ; http://php.net/session.sid-length
< ; Default Value: 32
< ; Development Value: 26
< ; Production Value: 26
< session.sid_length = 26
< 
< ; The URL rewriter will look for URLs in a defined set of HTML tags.
< ; <form> is special; if you include them here, the rewriter will
< ; add a hidden <input> field with the info which is otherwise appended
< ; to URLs. <form> tag's action attribute URL will not be modified
< ; unless it is specified.
< ; Note that all valid entries require a "=", even if no value follows.
< ; Default Value: "a=href,area=href,frame=src,form="
< ; Development Value: "a=href,area=href,frame=src,form="
< ; Production Value: "a=href,area=href,frame=src,form="
< ; http://php.net/url-rewriter.tags
< session.trans_sid_tags = "a=href,area=href,frame=src,form="
< 
< ; URL rewriter does not rewrite absolute URLs by default.
< ; To enable rewrites for absolute pathes, target hosts must be specified
< ; at RUNTIME. i.e. use ini_set()
< ; <form> tags is special. PHP will check action attribute's URL regardless
< ; of session.trans_sid_tags setting.
< ; If no host is defined, HTTP_HOST will be used for allowed host.
< ; Example value: php.net,www.php.net,wiki.php.net
< ; Use "," for multiple hosts. No spaces are allowed.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;session.trans_sid_hosts=""
---
> ; Select a hash function for use in generating session ids.
> ; Possible Values
> ;   0  (MD5 128 bits)
> ;   1  (SHA-1 160 bits)
> ; This option may also be set to the name of any hash function supported by
> ; the hash extension. A list of available hashes is returned by the hash_algos()
> ; function.
> ; http://php.net/session.hash-function
> session.hash_function = 0
1517c1457,1468
< session.sid_bits_per_character = 5
---
> session.hash_bits_per_character = 5
> 
> ; The URL rewriter will look for URLs in a defined set of HTML tags.
> ; form/fieldset are special; if you include them here, the rewriter will
> ; add a hidden <input> field with the info which is otherwise appended
> ; to URLs.  If you want XHTML conformity, remove the form entry.
> ; Note that all valid entries require a "=", even if no value follows.
> ; Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; http://php.net/url-rewriter.tags
> url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
1704c1655
< ;gd.jpeg_ignore_warning = 1
---
> ;gd.jpeg_ignore_warning = 0
1782c1733
< ;opcache.enable=1
---
> ;opcache.enable=0
1785c1736
< ;opcache.enable_cli=1
---
> ;opcache.enable_cli=0
1788c1739
< ;opcache.memory_consumption=128
---
> ;opcache.memory_consumption=64
1791c1742
< ;opcache.interned_strings_buffer=8
---
> ;opcache.interned_strings_buffer=4
1794,1795c1745,1746
< ; Only numbers between 200 and 1000000 are allowed.
< ;opcache.max_accelerated_files=10000
---
> ; Only numbers between 200 and 100000 are allowed.
> ;opcache.max_accelerated_files=2000
1823d1773
< ; Depending on the used Memory Manager this may cause some incompatibilities.
1893,1897d1842
< ; Implies opcache.file_cache_only=1 for a certain process that failed to
< ; reattach to the shared memory (for Windows only). Explicitly enabled file
< ; cache is required.
< ;opcache.file_cache_fallback=1
< 
1902,1907d1846
< ; Validate cached file permissions.
< ;opcache.validate_permission=0
< 
< ; Prevent name collisions in chroot'ed environment.
< ;opcache.validate_root=0
< 
```

変化があった項目は、個別に特にいじってなさそう。。
opcacheの有効/無効の設定に変化があったが、、
PHP7.0は元々無効だったのか自分で無効に変更したのか覚えてない。（調べてもない）

とりえあえず、、タイムゾーンをちゃんと設定してなかったことに今気づいた。。。

```
;date.timezone =
```

### 拡張モジュール

PHP 7.0の拡張モジュールを確認したけど、
apacheモジュールしか入れてなかった。（他にも入れてたつもりだったが・・・）

```
$ tree /usr/local/Cellar/php70/7.0.7/libexec/
/usr/local/Cellar/php70/7.0.7/libexec/
└── apache2
    └── libphp7.so
```

ローカルで開発するときはビルトインサーバを使っているので、
apacheモジュールはまあ必要なときに入れるとする。