MacでCakePHP3をComposerを使ってセットアップ

title

title

まずMacにHomebrew版のPHPをインストール。

参考 : MacのPHPをphp7へ変更(HomeBrewでPHP71のインストール)

PHP拡張のintlをインストール

CakePHPではIntl(国際化用拡張モジュール ICUのラッパー)が使われるので先にインストール

(参考サイト)
http://php.net/manual/ja/intro.intl.php
https://book.cakephp.org/3.0/ja/installation.html

brewを検索

$ brew search intl
homebrew/php/php53-intl     homebrew/php/php54-intl     homebrew/php/php55-intl     homebrew/php/php56-intl     homebrew/php/php70-intl     homebrew/php/php71-intl     homebrew/php/php72-intl     intltool

インストール

$ brew install php71-intl 
==> Installing php71-intl from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php71-intl-7.1.8_18.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php71-intl-7.1.8_18.sierra.bottle.tar.gz
==> Caveats
To finish installing intl for PHP 7.1:
  * /usr/local/etc/php/7.1/conf.d/ext-intl.ini was created,
    do not forget to remove it upon extension removal.
  * Validate installation via one of the following methods:
  *
  * Using PHP from a webserver:
  * - Restart your webserver.
  * - Write a PHP page that calls "phpinfo();"
  * - Load it in a browser and look for the info on the intl module.
  * - If you see it, you have been successful!
  *
  * Using PHP from the command line:
  * - Run `php -i "(command-line 'phpinfo()')"`
  * - Look for the info on the intl module.
  * - If you see it, you have been successful!
==> Summary
🍺  /usr/local/Cellar/php71-intl/7.1.8_18: 7 files, 552.6KB

プロジェクトをつくってみる

公式サイトを参考にcomposerのcreate-projectでプロジェクトを作ってみる。

(参考)
インストール | Cakephp
Composerのcreate-projectが何をやっているのか調べてみた

以下実行ろぐ。
composer self-updateは実行済で、途中で パーミッション設定する?(Set Folder Permissions ? (Default to Y) [Y,n]? y)と聞かれるのでyと答えた。

$ composer create-project --prefer-dist cakephp/app my_app_name
Installing cakephp/app (3.5.0)
  - Installing cakephp/app (3.5.0): Loading from cache
Created project in my_app_name
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 39 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.0.0): Downloading (100%)         
  - Installing aura/intl (3.0.0): Downloading (100%)         
  - Installing mobiledetect/mobiledetectlib (2.8.25): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing zendframework/zend-diactoros (1.4.1): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing cakephp/chronos (1.1.2): Downloading (100%)         
  - Installing cakephp/cakephp (3.5.0): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.5.0): Downloading (100%)         
  - Installing symfony/yaml (v3.3.6): Downloading (100%)         
  - Installing symfony/debug (v3.3.6): Downloading (100%)         
  - Installing symfony/console (v3.3.6): Downloading (100%)         
  - Installing symfony/filesystem (v3.3.6): Downloading (100%)         
  - Installing symfony/config (v3.3.6): Downloading (100%)         
  - Installing robmorgan/phinx (v0.8.1): Downloading (100%)         
  - Installing cakephp/migrations (1.7.1): Downloading (100%)         
  - Installing m1/env (2.1.0): Downloading (100%)         
  - Installing josegonzalez/dotenv (2.1.0): 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.1.0): Downloading (100%)         
  - Installing symfony/var-dumper (v3.3.6): Downloading (100%)         
  - Installing psy/psysh (v0.8.11): Downloading (100%)         
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)         
  - Installing symfony/process (v3.3.6): Downloading (100%)         
  - Installing symfony/finder (v3.3.6): Downloading (100%)         
  - Installing seld/phar-utils (1.0.1): Downloading (100%)         
  - Installing seld/jsonlint (1.6.1): Downloading (100%)         
  - Installing seld/cli-prompt (1.0.3): Downloading (100%)         
  - Installing justinrainbow/json-schema (5.2.1): 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.5.1): Downloading (100%)         
  - Installing cakephp/debug_kit (3.11.0): Downloading (100%)         
  - Installing cakephp/bake (1.4.1): Downloading (100%)         
  - Installing squizlabs/php_codesniffer (3.0.2): Downloading (100%)         
  - Installing cakephp/cakephp-codesniffer (3.0.1): 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 dereuromark/cakephp-ide-helper (After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.)
cakephp/app suggests installing phpunit/phpunit (Allows automated tests to be run without system-wide install.)
cakephp/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
symfony/console suggests installing symfony/event-dispatcher ()
m1/env suggests installing m1/vars (For loading of configs)
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
> CakeComposerInstallerPluginInstaller::postAutoloadDump
> AppConsoleInstaller::postInstall
Created `config/app.php` file
Set Folder Permissions ? (Default to Y) [Y,n]? y
Permissions set on /Users/taka/htdocs/my_app_name/tmp/cache
Permissions set on /Users/taka/htdocs/my_app_name/tmp/cache/models
Permissions set on /Users/taka/htdocs/my_app_name/tmp/cache/persistent
Permissions set on /Users/taka/htdocs/my_app_name/tmp/cache/views
Permissions set on /Users/taka/htdocs/my_app_name/tmp/sessions
Permissions set on /Users/taka/htdocs/my_app_name/tmp/tests
Permissions set on /Users/taka/htdocs/my_app_name/tmp
Permissions set on /Users/taka/htdocs/my_app_name/logs
Updated Security.salt value in config/app.php

ローカルサーバーを起動して確認

ローカルのApacheを起動して webrootをドキュメントルートに指定してアクセス。
うまく行った模様あとはDBとかsaltとか設定すれば大丈夫そう。パーミッションとか自動でやってくれるのは助かる。DBの設定とか、saltの設定などまとめて行うシェルスクリプトとか書いておくともっと楽にプロジェクト作れそうだけど、そこまで頻度ないか。

title

title