k-holyのPHPとか諸々メモ

Webで働くk-holyがPHP(スクリプト言語)とか諸々のことをメモしていきます。ソースコードはだいたいWindowsで動かしてます。

ローカル開発環境(Windows7)のPHPを5.5.16から5.6.0に更新した

ローカル開発環境(32bit Windows7)でのPHP 5.6への更新作業メモです。

アーカイブを展開してシンボリックリンクを切り替える

最新リリース版をダウンロード

過去バージョンの動作環境もそのまま残しておくため、シンボリックリンクで切り替えます。

mklink /d LINK TARGET コマンドで、アーカイブを展開したディレクトリにシンボリックリンクを切り替えます。Linuxのlnコマンドとは逆順です。(要管理者権限)

以下、シェルはNYAOSを使っています。

$ rmdir c:\php
$ mklink /d c:\php c:\php-5.6.0-Win32-VC11-x86

環境変数 Path には c:\php を設定しているので…。

$ php -v
PHP 5.6.0 (cli) (built: Aug 27 2014 11:54:39)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

OKです。

旧バージョンで追加/編集したファイルをコピーする

旧バージョンから追加/編集したファイルをコピーします。

  • composer.bat
  • composer.phar
  • php.ini

システム環境変数で PATH に c:\php を追加してPHP関連のコマンドを置いてる都合上、composerコマンドもコピーします。

ちなみにPEARを使っていた頃はここがPEARbin_dir でもあったため、PEARでインストールした Stagehand_TestRunner の testrunner コマンドと testrunner.bat もここにありました。

今はこちらの記事の通り、脱PEAR済みです。

新旧バージョンのphp.ini-developmentで変更箇所をチェックする

php.iniはとりあえず旧バージョンのものをコピーして編集しますが、まずは新旧のphp.ini-developmentを比較して変更箇所を差分ツール等で確認します。

今回の 5.5.16 → 5.6.0 に関しては微妙な英文の変更を除くと以下のような感じ。

マルチバイト関連

5.6.0では、default_charsetがUTF-8に指定されたのと、新たに internal_encoding, input_encoding, output_encoding ディレクティブが追加されています。

5.5.16

; PHP's default character set is set to empty.
; http://php.net/default-charset
;default_charset = "UTF-8"

5.6.0

; PHP's default character set is set to UTF-8
; http://php.net/default-charset
default_charset = "UTF-8"

; PHP internal character encoding is set to empty.
; If empty, default_charset is used.
; http://php.net/internal-encoding
;internal_encoding =

; PHP input character encoding is set to empty.
; If empty, default_charset is used.
; http://php.net/input-encoding
;input_encoding =

; PHP output character encoding is set to empty.
; If empty, default_charset is used.
; mbstring or iconv output handler is used.
; See also output_buffer.
; http://php.net/output-encoding
;output_encoding =

mbstringへの影響については後述。

$HTTP_RAW_POST_DATA

PHPマニュアルによれば -1 にすると将来のバージョンでの挙動に合わせられる、つまり $HTTP_RAW_POST_DATA が未定義となるようです。

5.5.16

; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature. If post reading is disabled through
; enable_post_data_reading, $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
;always_populate_raw_post_data = On

5.6.0

; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature and it will be removed in a future version.
; If post reading is disabled through enable_post_data_reading,
; $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
;always_populate_raw_post_data = -1

要するにデフォルト設定では未定義になったということかな。まあ、使っていないので関係ありません。

iconv

先ほど見た intput_encoding, internal_encoding, output_encoding ディレクティブの新設に合わせて、適用順序の説明が追加されています。

5.5.16

[iconv]
;iconv.input_encoding = ISO-8859-1
;iconv.internal_encoding = ISO-8859-1
;iconv.output_encoding = ISO-8859-1

5.6.0

[iconv]
; Use of this INI entry is deprecated, use global input_encoding instead.
; If empty, default_charset or input_encoding or iconv.input_encoding is used.
; The precedence is: default_charset < intput_encoding < iconv.input_encoding
;iconv.input_encoding =

; Use of this INI entry is deprecated, use global internal_encoding instead.
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
;iconv.internal_encoding =

; Use of this INI entry is deprecated, use global output_encoding instead.
; If empty, default_charset or output_encoding or iconv.output_encoding is used.
; The precedence is: default_charset < output_encoding < iconv.output_encoding
; To use an output encoding conversion, iconv's output handler must be set
; otherwise output encoding conversion cannot be performed.
;iconv.output_encoding =

iconvも使ってないので関係なし。

mbstring

こちらもiconvと同様、intput_encoding, internal_encoding, output_encoding ディレクティブの新設に合わせて、適用順序の説明などが追加されています。

5.5.16

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
; http://php.net/mbstring.internal-encoding
;mbstring.internal_encoding = UTF-8

; http input encoding.
; http://php.net/mbstring.http-input
;mbstring.http_input = UTF-8

; http output encoding. mb_output_handler must be
; registered as output buffer to function
; http://php.net/mbstring.http-output
;mbstring.http_output = pass

5.6.0

; Use of this INI entry is deprecated, use global internal_encoding instead.
; internal/script encoding.
; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
;mbstring.internal_encoding =

; Use of this INI entry is deprecated, use global input_encoding instead.
; http input encoding.
; mbstring.encoding_traslation = On is needed to use this setting.
; If empty, default_charset or input_encoding or mbstring.input is used.
; The precedence is: default_charset < intput_encoding < mbsting.http_input
; http://php.net/mbstring.http-input
;mbstring.http_input =

; Use of this INI entry is deprecated, use global output_encoding instead.
; http output encoding.
; mb_output_handler must be registered as output buffer to function.
; If empty, default_charset or output_encoding or mbstring.http_output is used.
; The precedence is: default_charset < output_encoding < mbstring.http_output
; To use an output encoding conversion, mbstring's output handler must be set
; otherwise output encoding conversion cannot be performed.
; http://php.net/mbstring.http-output
;mbstring.http_output =

この辺の設定は .htaccess とかアプリケーションのコードで変更しているので、あまり関係ないのですが、Use of this INI entry is deprecated とあります。

基本は default_charset のみ指定して、後はコメントアウトしておけば問題ないかと。つまり、5.6.0のデフォルト設定に従えばよし。

openssl

5.5.16にはなかった openssl モジュールのディレクティブが追加されています。

5.6.0

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
;openssl.cafile=

; If openssl.cafile is not specified or if the CA file is not found, the
; directory pointed to by openssl.capath is searched for a suitable
; certificate. This value must be a correctly hashed certificate directory.
; Most users should not specify a value for this directive as PHP will
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
;openssl.capath=

ここで指定しておくと、SSLコンテキストオプション のデフォルト値として使われるみたいです。

php.iniを編集する

新旧バージョンでチェックしたphp.ini-developmentの変更内容を取り込みます。

元々ポータビリティ重視でphp.iniは極力変更せずアプリケーション毎に .htaccess や ini_set() を使う方針なので、今回変更したのはここだけでした。

5.5.16

mbstring.http_output = pass

5.6.0

;mbstring.http_output =

その他には php_oci8.dll, php_oci8_11g.dll がなくなって php_oci8_12c.dll に変わってたりもしますが、使ってないので関係なし…。

自分で追加したextensionのDLLファイルを入手する

今回はマイナーバージョン更新のため、自分で追加したextensionのDLLファイルも入れ替えになると思います。(といっても今ではXdebugくらいしか使ってませんが…)

Xdebugは公式サイトでWindows用DLLファイルが提供されているので、これをダウンロードします。

インストールしたPHPのバージョンに合わせて選択します。今回はこちら。

c:\php\ext に保存して、php.iniの該当箇所を変更。

[XDebug]
zend_extension_ts = "ext/php_xdebug-2.2.5-5.6-vc11.dll"