読者です 読者をやめる 読者になる 読者になる

NissyBlog

Life goes on.

Mac OS XでCakePHP3の開発用サーバーを動かす

CakePHP

nissy0409.hatenablog.com

訳合って、こちらの環境と同じ環境をMac OS X上に構築しなくてはいけませんでした。
この時にも、

$ php composer.phar create-project --prefer-dist cakephp/app bookmarker
Installing cakephp/app (3.1.1)
  - Installing cakephp/app (3.1.1)
    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.2.x-dev 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-beta2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.1.0-beta requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.1.0-RC1 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.0-RC1, 3.1.0-beta, 3.1.0-beta2, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.2.x-dev].

前回同様にこの様なエラーが見られたので、どのように解消したかを書いていこうと思います。

こけた原因

今回も、php.intlが入って無くてインストール出来なかったという事実が判明しました。

対策

まず、足りないパッケージをbrewコマンドでインストールします。

$ brew update
$ brew search icu

続いて、下記コマンドを実行してPEERとPECLをインストール。

$ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar

下記コマンドを実行してphp.intlをインストールします。

$ sudo pecl update-channels
$ sudo pecl install intl

その後、/etc/php.iniに

extension=intl.so

を追記し、下記コマンドでapacheを再起動

sudo apachectl restart

先ほどbookmarkerディレクトリに作成したCakeのスケルトンを削除し、
もう一度、作り直してみます。

$ php composer.phar create-project --prefer-dist cakephp/app bookmarker
Installing cakephp/app (3.1.1)
  - Installing cakephp/app (3.1.1)
    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.2.x-dev 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-beta2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.1.0-beta requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.1.0-RC1 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.0-RC1, 3.1.0-beta, 3.1.0-beta2, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.2.x-dev].

本当の戦いはここからでした。

作戦変更

方々調べた結果、php.intlが未だに入っていないということが発覚しました。
そこで、php.intlの入れ方を調査したところ、
MacPortsでインストール出来るということが判明したため、
MacPortsを入れてみます。

sourceforge.net

こちらからMacPortsをインストールした後に、
下記コマンドを実行してパスを通します。

$ export PATH=/opt/local/bin:/opt/local/sbin:$PATH
$ export MANPATH=/opt/local/man:$MANPATH

パスを通した後、こちらのコマンドでphp.intl本体をインストールします。

$ sudo port install php54-intl

インストールが完了したら、下記コマンドを実行した後、

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

先ほどbookmarkerディレクトリに作成したCakeのスケルトンを削除し、
もう一度、作り直してみます。

$ php composer.phar create-project --prefer-dist cakephp/app bookmarker
Installing cakephp/app (3.1.1)
  - Installing cakephp/app (3.1.1)
    Loading from cache

Created project in bookmarker
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing aura/installer-default (1.0.0)
    Downloading: 100%

  - Installing cakephp/plugin-installer (0.0.12)
    Downloading: 100%

  - Installing psr/log (1.0.0)
    Downloading: 100%

  - Installing nesbot/carbon (1.13.0)
    Downloading: 100%

  - Installing mobiledetect/mobiledetectlib (2.8.17)
    Downloading: 100%

  - Installing aura/intl (1.1.1)
    Downloading: 100%

  - Installing ircmaxell/password-compat (v1.0.4)
    Downloading: 100%

  - Installing cakephp/cakephp (3.1.4)
    Downloading: 100%

  - Installing symfony/yaml (v2.7.6)
    Downloading: 100%

  - Installing symfony/filesystem (v2.7.6)
    Downloading: 100%

  - Installing symfony/config (v2.7.6)
    Downloading: 100%

  - Installing symfony/console (v2.7.6)
    Downloading: 100%

  - Installing robmorgan/phinx (dev-master 0674076)
    Downloading: 100%

  - Installing cakephp/migrations (1.4)
    Downloading: 100%

  - Installing jakub-onderka/php-console-color (0.1)
    Downloading: 100%

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Downloading: 100%

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Downloading: 100%

  - Installing nikic/php-parser (v1.4.1)
    Downloading: 100%

  - Installing symfony/var-dumper (v2.7.6)
    Downloading: 100%

  - Installing psy/psysh (v0.6.1)
    Downloading: 100%

  - Installing jdorn/sql-formatter (v1.2.17)
    Downloading: 100%

  - Installing cakephp/debug_kit (3.2.2)
    Downloading: 100%

  - Installing cakephp/bake (1.1.1)
    Downloading: 100%

symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/process ()
symfony/var-dumper suggests installing ext-symfony_debug ()
psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
cakephp/debug_kit suggests installing ext-sqlite (DebugKit needs to store panel data in a database. SQLite is simple and easy to use.)
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
Set Folder Permissions ? (Default to Y) [Y,n]? Y
Permissions set on /path/to/bookmarker/tmp/cache
Permissions set on /path/to/bookmarker/tmp/cache/models
Permissions set on /path/to/bookmarker/tmp/cache/persistent
Permissions set on /path/to/bookmarker/tmp/cache/views
Permissions set on /path/to/bookmarker/tmp/sessions
Permissions set on /path/to/bookmarker/tmp/tests
Permissions set on /path/to/bookmarker/tmp
Permissions set on /path/to/bookmarker/logs
Updated Security.salt value in config/app.php

明らかに先ほどとは出来具合が違います。
そこで、開発用サーバーを起動してみます。

$ bin/cake server

Welcome to CakePHP v3.1.4 Console
---------------------------------------------------------------
App : src
Path: /path/to/bookmarker/src/
DocumentRoot: /path/to/bookmarker/webroot
---------------------------------------------------------------
built-in server is running in http://localhost:8765/
You can exit with `CTRL-C`

無事、開発用サーバーが起動しました。

※参考
Installing Intl package on OSX Lion - Darragh Enright
Installing PHP PEAR and PECL extensions on MAMP for Mac OS X 10.7 (Lion) | Lullabot
ComposerでCakephp3をインストールしようとしてハマった件 | Into The World
MacPortsの基本的な使い方とコマンド : アシアルブログ