2008年10月26日(日)
apache+php+mysqlに関する文字コードについて CPIのVPS (2) [タイの電脳事情 電脳街情報]
apacheのhttpd.conf
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default. To use the
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
#AddDefaultCharset UTF-8
↑
必ずコメントアウトすること。
ここで文字コードを指定してしまうとメタタグがオーバーライトできなくなるからです。
同様に
/etc/php.ini
の default_charset ディレクティブをコメントアウトします。(何も指定しなくていいです。)
mbstringの設定は導入するウェブアプリによりますが、既存データがEUCという文字コードで保管されているので、↓のように設定しました。
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = auto
mbstring.encoding_translation = off
もちろんこの場合、mysqldのdefault-character-setもujis (EUC)になります。
特に重要なのはmy.cnfのmysqldセクションに文字コード自動変換機能スキップをするように下記のようなディレクティブを/etc/my.cnfの[mysqld]セクションに書いておくことです。
skip-character-set-client-handshake
Posted by ぷーちゃん at 00時09分