cloud9でのphp-mbstring対応についてのメモ

cloud9でのphp-mbstring対応

Cloud9でのマルチバイト対応についてメモ書きです。

現象

$pos = mb_strpos($name, $_POST['keywd']);
といった行で
Call to undefined function mb_strpos() in…というエラーになる。
この場合、php-mbstringがインストールされていない。

対応策

1. phpのバージョン確認

php -v

2. yumでインストール可能なmbstringを表示する

#yum list | grep mbstring

3. 1.で確認したPHPのバージョンと同じものをインストールする

sudo yum -y install php56-mbstring.x86_64

4. php.iniの編集

vi /etc/php.ini

php.iniの[mbstring]を下のように修正する。

[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstrig.detect_order.
; https://php.net/mbstring.language
mbstring.language = Japanese

; 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 = utf-8

; 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
; https://php.net/mbstring.http-input
mbstring.http_input = auto

; 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.
; https://php.net/mbstring.http-output
mbstring.http_output = utf-8

; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
;       portable libs/applications.
; https://php.net/mbstring.encoding-translation
mbstring.encoding_translation = On

; automatic encoding detection order.
; "auto" detect order is changed according to mbstring.language
; https://php.net/mbstring.detect-order
mbstring.detect_order = auto

もし書き込み権限のないユーザでファイルを編集してしまった場合、Can’t open file writing というエラーが出る
その場合は下記のコマンドでOK

:w !sudo tee %

5. apacheを再起動する

sudo service httpd restart

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です