LoginSignup
16
10

More than 5 years have passed since last update.

composer install で the requested PHP extension intl is missing from your system と言われる解決方法 in Docker image

Last updated at Posted at 2019-02-14

はじめに

自分が悩んだ順に書いていきます。無駄に長いです。
Dockerfileを扱ったのは今回が初めてです。初心者でも読みやすいと思います。
もっといい方法あるよというコメントお待ちしております。

エラー発生

nojimage/twitter-text-php
Twitterが公式で出しているライブラリがPHPに対応していなかったために導入
ローカル環境で下記コマンドを打つ
composer require nojimage/twitter-text-php

しかし下記のようにエラーが

shell
nojimage/twitter-text-php v3.0.1 requires ext-intl * -> the requested PHP extension intl is missing from your system.

PHPの拡張モジュールであるintlというものが無いらしい
PHP: intl - Manual
調べると国際化関数のあれこれが入ってるそう。
日本語含め多言語テキストをパースするために必要ってことだろうか。

intlの追加

docker-php-ext-installでPHP extensionは追加していけるそうだ。

Dockerfile
FROM php:7.?.?-fpm 
RUN apt-get update \
  && docker-php-ext-install pdo_mysql (省略) intl #intl追加

これでいけると思いdocker-compose up --buildでコンテナを立ち上げるとエラーが。

shell
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

どうやらICUというものが必要らしい。

ICUとはInternational Components for Unicodeのことで、
Unicodeに対する便利ライブラリ的なやつ。確かに国際化関数には必要そうだ。

ちなみに
International Christian University(国際基督教大学)でも、
Intensive Care Unit(集中治療室)でもない。
「ICU library」 で調べたら「図書館|国際基督教大学(ICU)」が出てきた

ICUの追加

今度はdocker-php-ext-installでは入らない
apt-get installでとってくる必要がある
詳細は割愛するが私は一度ここでaptではなくapkコマンド叩いてエラーになった。

Dockerfile
FROM php:7.?.?-fpm
RUN apt-get update \
    && apt-get install -y libicu-dev \ #一行追加
  && docker-php-ext-install pdo_mysql (省略) intl 

これでいけると思いコンテナを起動する。起動には成功。
docker exec -it hogehoge bashでコンテナに入り、
composer require nojimage/twitter-text-phpを再度実行するが、

shell
[RuntimeException]                                                                                                            
  Failed to clone https://github.com/nojimage/twitter-text-php.git, git was not found, check that it is installed and in your   
  PATH env.                                                                                                                     

  sh: 1: git: not found 

今度はgitが無いと怒られた。Docker内でcomposerを使うには必要らしい。

gitの追加

Dockerfile
FROM php:7.?.?-fpm
RUN apt-get update \
    && apt-get install -y libicu-dev git  \ #git追加
  && docker-php-ext-install pdo_mysql (省略) intl 

起動、入る、composerでまたしてもエラー

shell
Failed to download nojimage/twitter-text-php from dist: The zip extension and unzip command are both missing, skipping.
Your command-line PHP is using multiple ini files. Run `php --ini` to show them.

zipとunzipが無いようだ

zipとunzipの追加

The zip extension and unzip commandと表記がある通り、
zipはextensionでとれるがunzipはapt-getで入れる必要がある。

Dockerfile
FROM php:7.?.?-fpm
RUN apt-get update \
    && apt-get install -y libicu-dev git unzip  \ #unzip追加
  && docker-php-ext-install pdo_mysql (省略) intl zip #zip追加

今度は起動時にエラー

shell
configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

ZLIBが無いよとエラー。圧縮アルゴリズムのライブラリのようだ。

ZLIBの追加

Dockerfile
FROM php:7.?.?-fpm
RUN apt-get update \
    && apt-get install -y libicu-dev git unzip zlib1g-dev \ #zlib追加
  && docker-php-ext-install pdo_mysql (省略) intl zip 

この変更を最後に
docker-compose up --build
docker exec -it hogehoge bash
composer require nojimage/twitter-text-phpが通りました

最後に

Dockerfileも肥大化してしまったのであまりスマートなやり方ではない気が。
インフラ基礎知識が曖昧なままコンテナ技術を使っていたので並行して知識をつけていきたい。

下記の記事を参考にタイトルをつけました
composer install で the requested PHP extension intl is missing from your system と言われる解決方法

16
10
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
10