ComposerでCakephp3をインストールしようとしてハマった件

2017年10月26日

composerでcakephp3をインストールしようとしてはまりました。
7時間くらいハマりました。

開発環境
Mac OSX Marveriks
PHP 5.4.30
Apache/2.2.26 (Unix)

MAMPやXAMPPなどのソフトは使わず、MacにプリインストールされているPHPとApacheを利用しています。MysqlはHomebrewでインストール済み。composerはインストールしてある前提。

まずは、開発ディレクトリに移動。

[shell]
curl -s https://getcomposer.org/installer | php
[/shell]

で、composer.pharが作成される。
次に、Cakephp3をインストール

[shell]
php composer.phar create-project –prefer-dist cakephp/app test
[/shell]

すると、

[shell]
Your requirements could not be resolved to an installable set of packages.

Problem 1
– cakephp/cakephp 3.0.x-dev requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.1.x-dev requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.5 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.4 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.3 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-beta3 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-beta2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-beta1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-alpha2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-alpha1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-RC2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0-RC1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– cakephp/cakephp 3.0.0 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– Installation request for cakephp/cakephp ~3.0 -> satisfiable by cakephp/cakephp[3.0.0, 3.0.0-RC1, 3.0.0-RC2, 3.0.0-alpha1, 3.0.0-alpha2, 3.0.0-beta1, 3.0.0-beta2, 3.0.0-beta3, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.x-dev, 3.0.x-dev].
[/shell]

こんなエラーが。
PHP extension intlがないらしい。

調べると、

php.iniの設定で、extentionのコメントアウトを消せば、正常に動くとの事。

[shell]
sudo vim /etc/php.ini
[/shell]

下記の1行を挿入

[shell]
extension=intl.so
[/shell]

apache 再起動

[shell]
sudo apachectl restart
[/shell]

先ほど試した時に、実は途中までインストールできていたようで、testディレクトリが出来ているので、

[shell]
rm -rf test
[/shell]

でディレクトリを削除

もういちど

[shell]
php composer.phar create-project –prefer-dist cakephp/app test
[/shell]

先ほどとエラーは変わらず。

intlモジュール自体がないっぽい

intlがあるか調べる

[shell]
sudo find / -name *intl.so
[/shell]

ない。

ファイルが存在しない場合はintlモジュールをインストール必要がある。

調べると、peclでいれられるらしい

この辺りさんこうに
http://d.hatena.ne.jp/As_hsp/20120422/1335122128
http://qiita.com/ikemonn/items/45af7ede43b3d15d9d7a

[shell]
cd /tmp && mkdir pear && cd pear
$ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar
[/shell]

なんか聞かれたら基本 Enter

これでpeclとpearが使えるらしい

そこで、

[shell]
sudo pecl install intl

WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading intl-3.0.0.tgz …
Starting to download intl-3.0.0.tgz (248,200 bytes)
…………………………………………….done: 248,200 bytes
150 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Specify where ICU libraries and headers can be found [DEFAULT] :
[/shell]

と出て、Enterすると

[shell]
building in /private/tmp/pear/install/pear-build-rootpsbe7m/intl-3.0.0
running: /private/tmp/pear/install/intl/configure –with-icu-dir=DEFAULT
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
checking for a sed that does not truncate output… /usr/bin/sed
checking for cc… cc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether cc accepts -g… yes
checking for cc option to accept ISO C89… none needed
checking how to run the C preprocessor… cc -E
checking for icc… no
checking for suncc… no
checking whether cc understands -c and -o together… yes
checking for system library directory… lib
checking if compiler supports -R… no
checking if compiler supports -Wl,-rpath,… yes
checking build system type… i386-apple-darwin13.4.0
checking host system type… i386-apple-darwin13.4.0
checking target system type… i386-apple-darwin13.4.0
checking for PHP prefix… /usr
checking for PHP includes… -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory… /usr/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix… /usr/include/php
checking if debug is enabled… no
checking if zts is enabled… no
checking for re2c… no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk… no
checking for nawk… no
checking for awk… awk
checking if awk is broken… no
checking whether to enable internationalization support… yes, shared
checking for icu-config… no
checking for location of ICU headers and libraries… not found
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
ERROR: `/private/tmp/pear/install/intl/configure –with-icu-dir=DEFAULT’ failed
[/shell]

とエラーになる。

icuのなにかがエラーになる

http://freddyduarte.com/2013/08/14/installing-the-icu-libraries-and-the-php-intl-extension-on-a-mac/

これを参考に

[shell]
sudo pecl update-channels

Updating channel "doc.php.net"
Update of Channel "doc.php.net" succeeded
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
[/shell]

PATHを通す

[shell]
export PATH=$PATH:/Users/your_username/pear/bin
[/shell]

icuってのをいれなきゃ行けないらしい

http://site.icu-project.org/download/48#ICU4C

にいき、icu4c-4_8_1_1-src.tgz
をダウンロード

[shell]
tar -xvf icu4c-4_8_1_1-src.tgz
[/shell]

をするも、

[shell]
tar: Error opening archive: Failed to open ‘icu4c-4_8_1_1-src.tgz’
[/shell]

と怒られる

[shell]
brew install icu4c && brew link icu4c
[/shell]

Homebrewでいれようとしたら、
あった

[shell]
Warning: icu4c-55.1 already installed
Warning: icu4c is keg-only and must be linked with –force
Note that doing so can interfere with building software.
[/shell]

http://robinvdvleuten.nl/blog/install-the-intl-php-extension-in-mamp/

[shell]
curl -O http://download.icu-project.org/files/icu4c/4.8.1.1/icu4c-4_8_1_1-src.tgz
$ tar xzvf icu4c-4_8_1_1-src.tgz
$ cd icu/source
$ ./runConfigureICU MacOSX
$ make && sudo make install
[/shell]

なんかうまいこといったっぽい
これで、icuははいった

しかし

[shell]
pecl install intl
[/shell]

すると、しっぱい

[shell]
No releases available for package "pecl.php.net/intl"
install failed
[/shell]

あー、もうpeclでいれられない。。

仕方ない。

peclは諦めて他の手段で、intlいれるか。

調べてみると、macportsでいれられるらしい

macportsをインストール

http://qiita.com/us10096698/items/54195e60b7afb60105ef

macportsインストールできたけど、

なんかパス通ってなかったので自分で入れる
http://tukaikta.blog135.fc2.com/blog-entry-158.html

[shell]
port -v
MacPorts 2.3.3
Entering interactive mode… ("help" for help, "quit" to quit)
[/shell]

macports使える様になった

[shell]
sudo port install php54-intl
[/shell]

きたーーー!

しかし、composerでcakeをいれようとすると

[shell]
PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20100525/intl.so’ – dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/intl.so, 9): image not found in Unknown on line 0
[/shell]

imageがないとのこと。
php54-intlは入ってるはずなので、単に参照先にフォルダがない。

[shell]
sudo cp /opt/local/lib/php54/extensions/no-debug-non-zts-20100525/intl.so /usr/lib/php/extensions/no-debug-non-zts-20100525
[/shell]

これで、コピーする

そして、

composerをやると!

きたー!!!


composerでcakephp3

cakephp3かっこいい!

[参考URL]
http://pk-brothers.com/1705/
http://darraghenright.tumblr.com/post/22027208929/installing-intl-package-on-osx-lion
http://nagoring.com/blog/cakephp3-rc1-install-error/
http://d.hatena.ne.jp/As_hsp/20120422/1335122128
http://qiita.com/ikemonn/items/45af7ede43b3d15d9d7a
http://freddyduarte.com/2013/08/14/installing-the-icu-libraries-and-the-php-intl-extension-on-a-mac/
http://robinvdvleuten.nl/blog/install-the-intl-php-extension-in-mamp/
http://qiita.com/us10096698/items/54195e60b7afb60105ef
http://tukaikta.blog135.fc2.com/blog-entry-158.html