cakephp 3.xのチュートリアルをcomposerでインストールしようとしたらIntlがないと怒られてエラーになった際の対処方法についてメモ。正直かなりはまったので同様の問題で困っている人のためにメモしておきます。
composerのインストールは以下の手順で行った。
http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/blog.html
環境は以下の通り
- OS X Yosemite 10.10.5
- MAMP
- PHP 5.5.10
目次
Intlとはなんぞや?
http://php.net/manual/ja/intro.intl.phpより引用
国際化用拡張モジュール (これ以降では Intl と略します) は » ICU ライブラリのラッパーです。 PHP プログラマが、» UCA 準拠の照合順序 (collation) や日付/時刻/数値/通貨のフォーマットを扱えるようにします。
ICU の API に従って作成されているので、 C/C++ や Java で ICU を使ったことがあるかたは簡単に PHP の API も使えることでしょう。 また、ICU のドキュメントを参考にすればさまざまな ICU の関数について知ることができます。
Intl はいくつかのモジュールで構成されており、 各モジュールが対応する ICU API を公開しています。
-
- Collator: ロケールに応じた適切な並び順を考慮して、文字列の比較を行います。
- Number Formatter: 各地域固有の書式、あるいは指定した規則に基づいて数値を表示したり、 文字列を数値として解釈したりします。
- Message Formatter: メッセージ関連のデータ (数値や日付など) をパターンやロケールにあわせて適切にフォーマットしたり、 メッセージをパースしてデータを取り出したりします。
- Normalizer: テキストに対して Unicode の正規化を行ったり、 指定した文字列が正規化済みかどうかを調べたりします。
- Locale: ロケール識別子を扱うための機能を提供します。 たとえばロケール識別子のパースや作成、検索などを行います。
Composerのインストール
1 |
curl -s https://getcomposer.org/installer | php |
ここは問題なく無事に完了。
CalePHPのProject作成でintlのエラーが発生
ここで、the requested PHP extension intl is missing from your system.というエラーが発生した。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
MacBook-Pro:htdocs Username$ php composer.phar create-project --prefer-dist cakephp/app bookmarker Installing cakephp/app (3.1.2) - Installing cakephp/app (3.1.2) Loading from cache Created project in bookmarker Loading composer repositories with package information Installing dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - cakephp/cakephp 3.1.6 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.5 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.4 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.3 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.2 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.1 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.0 requires ext-intl * -> the requested PHP extension intl is missing from your system. - Installation request for cakephp/cakephp ~3.1 -> satisfiable by cakephp/cakephp[3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6]. |
以下のコマンドでインストールされているか確認するとHITなし。
1 |
php -m | grep intl |
じゃあ、intlとやらをインストールしようと試みたところネット上ではたくさんの解決方法があったのだが、自分の環境には合わずになかなか解決できなかった。色々と試した結果、自分が参考にしたサイトは以下で、手順通りに進めたら無事にインストールができた。
Installing Intl package on OSX Lion
Step 1. HomebrewとICUをインストール
1 2 3 |
$ brew update $ brew search icu # returns 'icu4c' $ brew install icu4c |
上記を実行したら、? /usr/local/Cellar/icu4c/56.1: 244 files, 63.7Mと表示された
Step 2. PECLでIntlをインストール
1 2 |
$ sudo pecl update-channels $ sudo pecl install intl |
Step 3. php.iniにextension=intl.soを登録
1 2 |
$ sudo cp /etc/php.ini{,.bak} # first, backup php.ini $ sudo vim /etc/php.ini |
php.iniファイルに以下を追加
1 |
extension=intl.so |
設定の反映
1 2 |
$ sudo apachectl -t $ sudo apachectl restart |
※もしphp.iniファイルを作っていなければ、/etc直下にphp.ini.defaultがあるはずなので、コピーしてphp.iniファイルを作る必要がある。
ファイルがあるがどうかを確認する↓↓
1 |
$ /etc/php.ini.default |
cpコマンドでphp.iniファイルを作成する↓↓
1 |
$ cp php.ini.default php.ini |
Step 4. 確認
1 |
$ php -m | grep intl # should return 'intl' |
intlと表示されれば無事にインストール完了です。これで無事にcomposerでcakekphpをインストールすることができました。お疲れさまでした。
その他にもこの辺が参考になった。
How to Enable INTL PHP Extension for MAMP on OSX 10.9.2
LEAVE A REPLY