LoginSignup
1
2

More than 3 years have passed since last update.

AWS エラー require ext-mbstringを解決

Posted at

はじめに

久々の面接を踏まえて自分のダメなところが少しわかったのでよかったです。
今回はEC2にcomposerをインストールした際にrequire ext-mbstringというエラーが発生したのでこれを解決できたので備忘録として投稿します。エラー文は下記になります。

 Problem 1
    - laravel/framework[v6.20.0, ..., 6.x-dev] require ext-mbstring * -> it is missing from your system. Install or enable PHP's mbstring extension.
    - Root composer.json requires laravel/framework ^6.20 -> satisfiable by laravel/framework[v6.20.0, ..., 6.x-dev].

投稿者の環境

MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)
macOS Big Sur バージョン11.0.1
PHP 7.3.23
Laravel Framework 6.20.7

エラー解決

ステップ1

EC2にてデプロイしたいappにcomposerをインストールします。

//EC2ターミナルにて
1. cd /var/www/sampleApp (これでディレクトリにチェンジ)
2. composer install

ステップ2

composer updateをして下さいと警告文が出ます。アップデートを実行すると下記の画像の様にエラーが出ます。

“スクリーンショット” 2020-12-22 11.27.48.jpg

ステップ3

phpとmbstringがないので下記を実行。
重要 phpのバージョンは各自必ず確認してから下記を実行して下さい!

//投稿者のphpのバージョンはphp7.3になります
sudo amazon-linux-extras install php7.3

// php-mbstringをインストール
sudo yum install php-mbstring

ステップ4

phpの設定ファイルであるphp.iniを編集します。ここでvimを使って編集作業をします。

sudo vim /etc/php.ini

;(セミコロン)を6箇所削除した後に保存をして下さい。編集する際は、バックアップして下さい。

[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; http://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
; http://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.
; http://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.
; http://php.net/mbstring.encoding-translation
mbstring.encoding_translation = On ←コメントを外して入力

; automatic encoding detection order.
; "auto" detect order is changed according to mbstring.language
; http://php.net/mbstring.detect-order
mbstring.detect_order = auto ←コメントを外して入力

~以下略~

ステップ5

sudo service httpd restartを実行してアパッチを再起動させて下さい。最後にcomposer updateを実行すると解決ができました。

番外編1

composer installを違う場所にインストールすると下記のエラーが出てきます。

Warning: require(/project/vendor/autoload.php): failed to open stream: No such file or directory in /project/artisan on line 18

Fatal error: require(): Failed opening required '/project/vendor/autoload.php' (include_path='.:') in /project/artisan on line 18

これを解決するためのHPが以下になります。

Laravelで…vendor/autoload.php): failed to open stream: No such file or directory というエラーによりデフォルト画面が表示されない解決方法

番外編2

vendorフォルダとは?
依存内容をおくところ。つまり、この中にComposerのライブラリ(プログラムの部分的なパーツみたいなもの)を格納するフォルダみたいなもの。

参考文献

思考の葉
Amazon linux2でphp-mbstring有効化
Laravelで…vendor/autoload.php): failed to open stream: No such file or directory というエラーによりデフォルト画面が表示されない解決方法

1
2
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
1
2