Mac OS XでのCakePHPインストール

# はじめに

ウェブサーバやDBの設定は省いたCakePHP本体のみのインストールとCakePHPアプリケーション初期構築までを実施した際のメモです。

## 動作確認環境
- Mas OS 10.12.3
- PHP 5.6.28
- Homebrew 1.1.12
- Composer 1.4.1
- CakePHP 3.4.5

# Composerのインストール

最初に依存性管理ツールのcomposerをインストールします。
https://book.cakephp.org/3.0/ja/installation.html
https://getcomposer.org/download/ を参考に

```shell-session
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php -r "unlink('composer-setup.php');"
$ mv composer.phar /usr/local/bin/composer
$ php /usr/local/bin/composer create
```
/usr/local/bin にはPATHが通っている前提で動作確認

```shell-session
$ composer self-update
You are already using composer version 1.4.1 (stable channel).
```
OK

# CakePHPの新しいアプリケーション作成

カレントディレクトリ直下のtestappというディレクトリに作成する前提です。

```shell-session
$ composer create-project --prefer-dist cakephp/app testapp


Installing cakephp/app (3.4.1)
  - Installing cakephp/app (3.4.1): Downloading (100%)         
Created project in testapp
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - cakephp/cakephp 3.4.5 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.4.4 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.4.3 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.4.2 requires lib-icu >=4.8 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    - cakephp/cakephp 3.4.1 requires lib-icu >=4.8 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    - cakephp/cakephp 3.4.0 requires lib-icu >=4.8 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    - Installation request for cakephp/cakephp 3.4.* -> satisfiable by cakephp/cakephp[3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5].
```

ext-intl(Internationalizationのextension)かlib-icu(International Components for UnicodeのLibrary)が無いと怒られました。

## ext-intlのインストール

よって、homebrewでext-intlを入れます。

```shell-session
$ brew search intl
intltool
homebrew/php/php53-intl                     homebrew/php/php55-intl                     homebrew/php/php70-intl
homebrew/php/php54-intl                     homebrew/php/php56-intl                     homebrew/php/php71-intl
$ php -v
PHP 5.6.28 (cli) (built: Dec  6 2016 12:38:54) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ brew install homebrew/php/php56-intl
==> Tapping homebrew/php
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-php'...
remote: Counting objects: 694, done.
remote: Compressing objects: 100% (472/472), done.
remote: Total 694 (delta 454), reused 300 (delta 217), pack-reused 0
Receiving objects: 100% (694/694), 286.28 KiB | 0 bytes/s, done.
Resolving deltas: 100% (454/454), done.
Tapped 664 formulae (709 files, 1.3MB)
==> Installing php56-intl from homebrew/php
==> Installing dependencies for homebrew/php/php56-intl: libxml2, unixodbc, php56
==> Installing homebrew/php/php56-intl dependency: libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.4_2.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring libxml2-2.9.4_2.sierra.bottle.1.tar.gz
（略）
==> Summary
🍺  /usr/local/Cellar/libxml2/2.9.4_2: 277 files, 9.8MB
==> Installing homebrew/php/php56-intl dependency: unixodbc
==> Downloading https://homebrew.bintray.com/bottles/unixodbc-2.3.4.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring unixodbc-2.3.4.sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/unixodbc/2.3.4: 43 files, 2.0MB
==> Installing homebrew/php/php56-intl dependency: php56
==> Downloading https://homebrew.bintray.com/bottles-php/php56-5.6.30_6.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php56-5.6.30_6.sierra.bottle.tar.gz
（略）
==> Summary
🍺  /usr/local/Cellar/php56/5.6.30_6: 331 files, 38.0MB
==> Installing homebrew/php/php56-intl 
==> Downloading https://homebrew.bintray.com/bottles-php/php56-intl-5.6.30_7.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php56-intl-5.6.30_7.sierra.bottle.tar.gz
（略）
==> Summary
🍺  /usr/local/Cellar/php56-intl/5.6.30_7: 6 files, 873.5KB
```

intlだけでなくて5.6.30本体も/usr/local/Cellar/php56に入ってしまいましたが、

```shell-session
$ /usr/local/Cellar/php56/5.6.30_6/bin/php -v
PHP 5.6.30 (cli) (built: Mar 11 2017 09:56:27) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
```


とりあえず進めます。testapp2 の名前でアプリケーション作成します。


```
$ composer create-project --prefer-dist cakephp/app testapp2
Installing cakephp/app (3.4.1)
  - Installing cakephp/app (3.4.1): Loading from cache
Created project in testapp2
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 35 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.0.0): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing zendframework/zend-diactoros (1.4.0): Downloading (100%)         
  - Installing aura/intl (3.0.0): Downloading (100%)         
  - Installing mobiledetect/mobiledetectlib (2.8.25): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing cakephp/chronos (1.1.1): Downloading (100%)         
  - Installing cakephp/cakephp (3.4.5): Downloading (100%)         
  - Installing symfony/yaml (v3.2.7): Downloading (100%)         
  - Installing symfony/debug (v3.2.7): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.3.0): Downloading (100%)         
  - Installing symfony/console (v3.2.7): Downloading (100%)         
  - Installing symfony/filesystem (v3.2.7): Downloading (100%)         
  - Installing symfony/config (v3.2.7): Downloading (100%)         
  - Installing robmorgan/phinx (v0.6.5): Downloading (100%)         
  - Installing cakephp/migrations (1.6.7): 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 (v3.0.5): Downloading (100%)         
  - Installing symfony/var-dumper (v3.2.7): Downloading (100%)         
  - Installing psy/psysh (v0.8.3): Downloading (100%)         
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)         
  - Installing symfony/process (v3.2.7): Downloading (100%)         
  - Installing symfony/finder (v3.2.7): Downloading (100%)         
  - Installing seld/phar-utils (1.0.1): Downloading (100%)         
  - Installing seld/jsonlint (1.6.0): Downloading (100%)         
  - Installing seld/cli-prompt (1.0.3): Downloading (100%)         
  - Installing justinrainbow/json-schema (5.2.0): Downloading (100%)         
  - Installing composer/spdx-licenses (1.1.6): Downloading (100%)         
  - Installing composer/semver (1.4.2): Downloading (100%)         
  - Installing composer/ca-bundle (1.0.7): Downloading (100%)         
  - Installing composer/composer (1.4.1): Downloading (100%)         
  - Installing cakephp/debug_kit (3.9.3): Downloading (100%)         
  - Installing cakephp/bake (1.3.3): Downloading (100%)         
cakephp/app suggests installing markstory/asset_compress (An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.)
cakephp/app suggests installing phpunit/phpunit (Allows automated tests to be run without system-wide install.)
cakephp/app suggests installing cakephp/cakephp-codesniffer (Allows to check the code against the coding standards used in CakePHP.)
cakephp/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
symfony/console suggests installing symfony/event-dispatcher ()
symfony/var-dumper suggests installing ext-symfony_debug ()
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
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 /Users/qiita/dev/PHP/cake/testapp2/tmp/cache
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp/cache/models
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp/cache/persistent
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp/cache/views
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp/sessions
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp/tests
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/tmp
Permissions set on /Users/qiita/dev/PHP/cake/testapp2/logs
Updated Security.salt value in config/app.php
```

今度は成功したようです。

とりあえず server を起動してみます。

```shell-session
$ cd testapp2
$ bin/cake server

Welcome to CakePHP v3.4.5 Console
---------------------------------------------------------------
App : src
Path: /Users/qiita/dev/PHP/cake/testapp2/src/
DocumentRoot: /Users/qiita/dev/PHP/cake/testapp2/webroot
---------------------------------------------------------------
built-in server is running in http://localhost:8765/
You can exit with `CTRL-C`
```

起動しました。
別ターミナルで

```shell-session
$ curl -I  http://localhost:8765/
HTTP/1.1 200 OK
Host: localhost:8765
Connection: close
X-Powered-By: PHP/5.6.30
Content-Type: text/html; charset=UTF-8
X-DEBUGKIT-ID: d2cdefc7-57cb-4739-a379-1b39dbdcaf91

```

接続OKのようです。
ここまで