LoginSignup
16
16

More than 5 years have passed since last update.

Amazon Linuxでphpでmbstringを使う

Last updated at Posted at 2017-04-13

しょぼい記事ですみません。

環境

Amazon EC2 / AWS
Linux ip-xxx-xx-xx-xx 4.9.17-8.31.amzn1.x86_64
実行日: 2017-04-13
バージョン: php7
ディストリビューションは、amazon linux (CentOSベースの無償のもの)

事前に、以下の手順にそってインストール
http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/install-LAMP.html

困ったこと

頂き物のphpを動かしてみたら、エラーログでmb_substrがないと怒られる。。

[Thu Apr 13 02:05:37.287787 2017] [:error] [pid 32557] [client xxx.xxx.xxx.xxx:61072] PHP Fatal error:  Uncaught Error: Call to undefined function mb_substr() in /var/www/html/xxx/xxx.php:82\nStack trace:\n#0 {main}\n  thrown in /var/www/html/xxx/xxx.php on line 82, referer: http://xxx.xxx.xxx.xxx/xxx/top.php

現状確認

mbモジュールが入ってないっぽい。

[root@ip-xxx-xx-xx-xx etc]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zlib

[Zend Modules]

解決策

yumでインストール

[root@ip-xxx-xx-xx-xx php.d]# php -v
PHP 7.0.16 (cli) (built: Mar  6 2017 19:45:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

[root@ip-xxx-xx-xx-xx php.d]# yum list | grep "\-mbstring"
php-mbstring.x86_64                     5.3.29-1.8.amzn1               amzn-main
php54-mbstring.x86_64                   5.4.45-1.75.amzn1              amzn-main
php55-mbstring.x86_64                   5.5.38-2.119.amzn1             amzn-main
php56-mbstring.x86_64                   5.6.30-1.133.amzn1             amzn-main
php70-mbstring.x86_64                   7.0.16-1.21.amzn1              amzn-main

[root@ip-xxx-xx-xx-xx php.d]# yum install php70-mbstring.x86_64
読み込んだプラグイン:priorities, update-motd, upgrade-helper
1004 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ php70-mbstring.x86_64 0:7.0.16-1.21.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

==================================================================================================================
 Package                      アーキテクチャー     バージョン                       リポジトリー             容量
==================================================================================================================
インストール中:
 php70-mbstring               x86_64               7.0.16-1.21.amzn1                amzn-main               1.3 M

トランザクションの要約
==================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 1.3 M
インストール容量: 2.7 M
Is this ok [y/d/N]: y
Downloading packages:
php70-mbstring-7.0.16-1.21.amzn1.x86_64.rpm                                                | 1.3 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : php70-mbstring-7.0.16-1.21.amzn1.x86_64                                           1/1 
  検証中                  : php70-mbstring-7.0.16-1.21.amzn1.x86_64                                           1/1 

インストール:
  php70-mbstring.x86_64 0:7.0.16-1.21.amzn1                                                                       

完了しました!

# ここで再起動
[root@ip-xxx-xx-xx-xx php.d]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

動作確認

[root@ip-xxx-xx-xx-xx php.d]# php -m | grep mb
mbstring

めでたしめでたし。

ちなみに、設定ファイル(/etc/phpini)は、以下のサイトを参考にしました。
http://qiita.com/yamaguchi_takashi/items/d4b7b2693b42679dc3ae
(バージョンは違いますが、mbstringについてはほとんど同じです。)

16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16