PHP8+CakePHP4の環境構築

CakePHP

Macを新調したので、開発環境構築します。

Webアプリ作成用に、CakePHP4の環境を作成します。Larvelとどっちにしようか迷ったんですが、以前のMacではLaravelで作っていたので今回は違うやつにしようということでCakePHPに。

環境構築しますって言っても、公式ドキュメント読んでその通りにするだけです。特別なことはしません。

今回は開発用サーバーで起動できるところまで進めます。Webサーバーに載せるのはまた今度。

バージョン確認

PHP

~/D/Dev ❯❯❯ php -v
PHP 8.0.0 (cli) (built: Dec  8 2020 22:00:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

Composer

~/D/Dev ❯❯❯ composer --version
Composer version 2.0.8 2020-12-03 17:20:38

CakePHPの環境構築

公式ドキュメントのインストレーションにあるproject作成コマンドを実行します。

~/D/Dev ❯❯❯ composer create-project --prefer-dist cakephp/app:~4.0 cake_app
Creating a "cakephp/app:~4.0" project at "./cake_app"
Installing cakephp/app (4.1.2)
  - Installing cakephp/app (4.1.2): Extracting archive
Created project in /Users/home/Documents/Dev/cake_app
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - cakephp/cakephp[4.1.0, ..., 4.1.6] require aura/intl ^3.0.0 -> satisfiable by aura/intl[3.0.0].
    - aura/intl 3.0.0 requires php ^5.6|^7.0 -> your php version (8.0.0) does not satisfy that requirement.
    - Root composer.json requires cakephp/cakephp ~4.1.0 -> satisfiable by cakephp/cakephp[4.1.0, ..., 4.1.6].

依存先のaura/intlがPHP8を許容していないようです。今回はそれを無視して構築したいので、チェック回避オプション(–ignore-platform-reqs)を追加して再度実行します。

~/D/Dev ❯❯❯ rm -rf cake_app
~/D/Dev ❯❯❯ composer create-project --prefer-dist --ignore-platform-reqs cakephp/app:~4.0 cake_app
Creating a "cakephp/app:~4.0" project at "./cake_app"
Installing cakephp/app (4.1.2)
  - Installing cakephp/app (4.1.2): Extracting archive
Created project in /Users/home/Documents/Dev/cake_app
Loading composer repositories with package information
Updating dependencies
Lock file operations: 87 installs, 0 updates, 0 removals
  - Locking aura/intl (3.0.0)
  - Locking cakephp/bake (2.3.0)
  - Locking cakephp/cakephp (4.1.6)
  - Locking cakephp/cakephp-codesniffer (4.2.4)
  - Locking cakephp/chronos (2.0.6)
  - Locking cakephp/debug_kit (4.3.9)
  - Locking cakephp/migrations (3.0.0)
  - Locking cakephp/plugin-installer (1.3.1)
  - Locking cakephp/twig-view (1.1.1)
  - Locking composer/ca-bundle (1.2.8)
  - Locking composer/composer (2.0.8)
  - Locking composer/semver (3.2.4)
  - Locking composer/spdx-licenses (1.5.5)
  - Locking composer/xdebug-handler (1.4.5)
  - Locking dealerdirect/phpcodesniffer-composer-installer (v0.7.1)
  - Locking dnoegel/php-xdg-base-dir (v0.1.1)
  - Locking doctrine/instantiator (1.4.0)
  - Locking jasny/twig-extensions (v1.3.0)
  - Locking jdorn/sql-formatter (v1.2.17)
  - Locking josegonzalez/dotenv (3.2.0)
  - Locking justinrainbow/json-schema (5.2.10)
  - Locking laminas/laminas-diactoros (2.5.0)
  - Locking laminas/laminas-httphandlerrunner (1.3.0)
  - Locking laminas/laminas-zendframework-bridge (1.1.1)
  - Locking m1/env (2.2.0)
  - Locking mobiledetect/mobiledetectlib (2.8.34)
  - Locking myclabs/deep-copy (1.10.2)
  - Locking nikic/php-parser (v4.10.3)
  - Locking phar-io/manifest (2.0.1)
  - Locking phar-io/version (3.0.3)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.2.2)
  - Locking phpdocumentor/type-resolver (1.4.0)
  - Locking phpspec/prophecy (1.12.1)
  - Locking phpstan/phpdoc-parser (0.4.9)
  - Locking phpunit/php-code-coverage (7.0.14)
  - Locking phpunit/php-file-iterator (2.0.3)
  - Locking phpunit/php-text-template (1.2.1)
  - Locking phpunit/php-timer (2.1.3)
  - Locking phpunit/php-token-stream (4.0.4)
  - Locking phpunit/phpunit (8.5.13)
  - Locking psr/container (1.0.0)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/http-server-handler (1.0.1)
  - Locking psr/http-server-middleware (1.0.1)
  - Locking psr/log (1.1.3)
  - Locking psr/simple-cache (1.0.1)
  - Locking psy/psysh (v0.10.5)
  - Locking react/promise (v2.8.0)
  - Locking robmorgan/phinx (0.12.4)
  - Locking sebastian/code-unit-reverse-lookup (1.0.2)
  - Locking sebastian/comparator (3.0.3)
  - Locking sebastian/diff (3.0.3)
  - Locking sebastian/environment (4.2.4)
  - Locking sebastian/exporter (3.1.3)
  - Locking sebastian/global-state (3.0.1)
  - Locking sebastian/object-enumerator (3.0.4)
  - Locking sebastian/object-reflector (1.1.2)
  - Locking sebastian/recursion-context (3.0.1)
  - Locking sebastian/resource-operations (2.0.2)
  - Locking sebastian/type (1.1.4)
  - Locking sebastian/version (2.0.1)
  - Locking seld/jsonlint (1.8.3)
  - Locking seld/phar-utils (1.1.1)
  - Locking slevomat/coding-standard (6.4.1)
  - Locking squizlabs/php_codesniffer (3.5.8)
  - Locking symfony/config (v5.2.0)
  - Locking symfony/console (v5.2.0)
  - Locking symfony/deprecation-contracts (v2.2.0)
  - Locking symfony/filesystem (v5.2.0)
  - Locking symfony/finder (v5.2.0)
  - Locking symfony/polyfill-ctype (v1.20.0)
  - Locking symfony/polyfill-intl-grapheme (v1.20.0)
  - Locking symfony/polyfill-intl-normalizer (v1.20.0)
  - Locking symfony/polyfill-mbstring (v1.20.0)
  - Locking symfony/polyfill-php73 (v1.20.0)
  - Locking symfony/polyfill-php80 (v1.20.0)
  - Locking symfony/process (v5.2.0)
  - Locking symfony/service-contracts (v2.2.0)
  - Locking symfony/string (v5.2.0)
  - Locking symfony/var-dumper (v5.2.0)
  - Locking theseer/tokenizer (1.2.0)
  - Locking twig/markdown-extra (v3.1.1)
  - Locking twig/twig (v3.1.1)
  - Locking webmozart/assert (1.9.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 87 installs, 0 updates, 0 removals
  - Downloading cakephp/plugin-installer (1.3.1)
  - Downloading squizlabs/php_codesniffer (3.5.8)
  - Downloading dealerdirect/phpcodesniffer-composer-installer (v0.7.1)
  - Downloading aura/intl (3.0.0)
  - Downloading symfony/polyfill-mbstring (v1.20.0)
  - Downloading symfony/polyfill-ctype (v1.20.0)
  - Downloading twig/twig (v3.1.1)
  - Downloading twig/markdown-extra (v3.1.1)
  - Downloading jasny/twig-extensions (v1.3.0)
  - Downloading psr/simple-cache (1.0.1)
  - Downloading psr/log (1.1.3)
  - Downloading psr/http-message (1.0.1)
  - Downloading psr/http-server-handler (1.0.1)
  - Downloading psr/http-server-middleware (1.0.1)
  - Downloading psr/http-client (1.0.1)
  - Downloading psr/http-factory (1.0.1)
  - Downloading laminas/laminas-zendframework-bridge (1.1.1)
  - Downloading laminas/laminas-diactoros (2.5.0)
  - Downloading laminas/laminas-httphandlerrunner (1.3.0)
  - Downloading composer/ca-bundle (1.2.8)
  - Downloading cakephp/chronos (2.0.6)
  - Downloading cakephp/cakephp (4.1.6)
  - Downloading cakephp/twig-view (1.1.1)
  - Downloading cakephp/bake (2.3.0)
  - Downloading phpstan/phpdoc-parser (0.4.9)
  - Downloading slevomat/coding-standard (6.4.1)
  - Downloading cakephp/cakephp-codesniffer (4.2.4)
  - Downloading jdorn/sql-formatter (v1.2.17)
  - Downloading symfony/polyfill-php80 (v1.20.0)
  - Downloading symfony/process (v5.2.0)
  - Downloading symfony/finder (v5.2.0)
  - Downloading symfony/filesystem (v5.2.0)
  - Downloading symfony/polyfill-intl-normalizer (v1.20.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.20.0)
  - Downloading symfony/string (v5.2.0)
  - Downloading psr/container (1.0.0)
  - Downloading symfony/service-contracts (v2.2.0)
  - Downloading symfony/polyfill-php73 (v1.20.0)
  - Downloading symfony/console (v5.2.0)
  - Downloading seld/phar-utils (1.1.1)
  - Downloading seld/jsonlint (1.8.3)
  - Downloading react/promise (v2.8.0)
  - Downloading justinrainbow/json-schema (5.2.10)
  - Downloading composer/xdebug-handler (1.4.5)
  - Downloading composer/spdx-licenses (1.5.5)
  - Downloading composer/semver (3.2.4)
  - Downloading composer/composer (2.0.8)
  - Downloading cakephp/debug_kit (4.3.9)
  - Downloading symfony/deprecation-contracts (v2.2.0)
  - Downloading symfony/config (v5.2.0)
  - Downloading robmorgan/phinx (0.12.4)
  - Downloading cakephp/migrations (3.0.0)
  - Downloading m1/env (2.2.0)
  - Downloading josegonzalez/dotenv (3.2.0)
  - Downloading mobiledetect/mobiledetectlib (2.8.34)
  - Downloading webmozart/assert (1.9.1)
  - Downloading phpdocumentor/reflection-common (2.2.0)
  - Downloading phpdocumentor/type-resolver (1.4.0)
  - Downloading phpdocumentor/reflection-docblock (5.2.2)
  - Downloading phpunit/php-token-stream (4.0.4)
  - Downloading sebastian/version (2.0.1)
  - Downloading sebastian/type (1.1.4)
  - Downloading sebastian/resource-operations (2.0.2)
  - Downloading sebastian/recursion-context (3.0.1)
  - Downloading sebastian/object-reflector (1.1.2)
  - Downloading sebastian/object-enumerator (3.0.4)
  - Downloading sebastian/global-state (3.0.1)
  - Downloading sebastian/exporter (3.1.3)
  - Downloading sebastian/environment (4.2.4)
  - Downloading sebastian/diff (3.0.3)
  - Downloading sebastian/comparator (3.0.3)
  - Downloading phpunit/php-timer (2.1.3)
  - Downloading phpunit/php-text-template (1.2.1)
  - Downloading phpunit/php-file-iterator (2.0.3)
  - Downloading theseer/tokenizer (1.2.0)
  - Downloading sebastian/code-unit-reverse-lookup (1.0.2)
  - Downloading phpunit/php-code-coverage (7.0.14)
  - Downloading doctrine/instantiator (1.4.0)
  - Downloading phpspec/prophecy (1.12.1)
  - Downloading phar-io/version (3.0.3)
  - Downloading phar-io/manifest (2.0.1)
  - Downloading myclabs/deep-copy (1.10.2)
  - Downloading phpunit/phpunit (8.5.13)
  - Downloading symfony/var-dumper (v5.2.0)
  - Downloading nikic/php-parser (v4.10.3)
  - Downloading dnoegel/php-xdg-base-dir (v0.1.1)
  - Downloading psy/psysh (v0.10.5)
  - Installing cakephp/plugin-installer (1.3.1): Extracting archive
  - Installing squizlabs/php_codesniffer (3.5.8): Extracting archive
  - Installing dealerdirect/phpcodesniffer-composer-installer (v0.7.1): Extracting archive
  - Installing aura/intl (3.0.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.20.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.20.0): Extracting archive
  - Installing twig/twig (v3.1.1): Extracting archive
  - Installing twig/markdown-extra (v3.1.1): Extracting archive
  - Installing jasny/twig-extensions (v1.3.0): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing psr/log (1.1.3): Extracting archive
  - Installing psr/http-message (1.0.1): Extracting archive
  - Installing psr/http-server-handler (1.0.1): Extracting archive
  - Installing psr/http-server-middleware (1.0.1): Extracting archive
  - Installing psr/http-client (1.0.1): Extracting archive
  - Installing psr/http-factory (1.0.1): Extracting archive
  - Installing laminas/laminas-zendframework-bridge (1.1.1): Extracting archive
  - Installing laminas/laminas-diactoros (2.5.0): Extracting archive
  - Installing laminas/laminas-httphandlerrunner (1.3.0): Extracting archive
  - Installing composer/ca-bundle (1.2.8): Extracting archive
  - Installing cakephp/chronos (2.0.6): Extracting archive
  - Installing cakephp/cakephp (4.1.6): Extracting archive
  - Installing cakephp/twig-view (1.1.1): Extracting archive
  - Installing cakephp/bake (2.3.0): Extracting archive
  - Installing phpstan/phpdoc-parser (0.4.9): Extracting archive
  - Installing slevomat/coding-standard (6.4.1): Extracting archive
  - Installing cakephp/cakephp-codesniffer (4.2.4): Extracting archive
  - Installing jdorn/sql-formatter (v1.2.17): Extracting archive
  - Installing symfony/polyfill-php80 (v1.20.0): Extracting archive
  - Installing symfony/process (v5.2.0): Extracting archive
  - Installing symfony/finder (v5.2.0): Extracting archive
  - Installing symfony/filesystem (v5.2.0): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.20.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.20.0): Extracting archive
  - Installing symfony/string (v5.2.0): Extracting archive
  - Installing psr/container (1.0.0): Extracting archive
  - Installing symfony/service-contracts (v2.2.0): Extracting archive
  - Installing symfony/polyfill-php73 (v1.20.0): Extracting archive
  - Installing symfony/console (v5.2.0): Extracting archive
  - Installing seld/phar-utils (1.1.1): Extracting archive
  - Installing seld/jsonlint (1.8.3): Extracting archive
  - Installing react/promise (v2.8.0): Extracting archive
  - Installing justinrainbow/json-schema (5.2.10): Extracting archive
  - Installing composer/xdebug-handler (1.4.5): Extracting archive
  - Installing composer/spdx-licenses (1.5.5): Extracting archive
  - Installing composer/semver (3.2.4): Extracting archive
  - Installing composer/composer (2.0.8): Extracting archive
  - Installing cakephp/debug_kit (4.3.9): Extracting archive
  - Installing symfony/deprecation-contracts (v2.2.0): Extracting archive
  - Installing symfony/config (v5.2.0): Extracting archive
  - Installing robmorgan/phinx (0.12.4): Extracting archive
  - Installing cakephp/migrations (3.0.0): Extracting archive
  - Installing m1/env (2.2.0): Extracting archive
  - Installing josegonzalez/dotenv (3.2.0): Extracting archive
  - Installing mobiledetect/mobiledetectlib (2.8.34): Extracting archive
  - Installing webmozart/assert (1.9.1): Extracting archive
  - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
  - Installing phpdocumentor/type-resolver (1.4.0): Extracting archive
  - Installing phpdocumentor/reflection-docblock (5.2.2): Extracting archive
  - Installing phpunit/php-token-stream (4.0.4): Extracting archive
  - Installing sebastian/version (2.0.1): Extracting archive
  - Installing sebastian/type (1.1.4): Extracting archive
  - Installing sebastian/resource-operations (2.0.2): Extracting archive
  - Installing sebastian/recursion-context (3.0.1): Extracting archive
  - Installing sebastian/object-reflector (1.1.2): Extracting archive
  - Installing sebastian/object-enumerator (3.0.4): Extracting archive
  - Installing sebastian/global-state (3.0.1): Extracting archive
  - Installing sebastian/exporter (3.1.3): Extracting archive
  - Installing sebastian/environment (4.2.4): Extracting archive
  - Installing sebastian/diff (3.0.3): Extracting archive
  - Installing sebastian/comparator (3.0.3): Extracting archive
  - Installing phpunit/php-timer (2.1.3): Extracting archive
  - Installing phpunit/php-text-template (1.2.1): Extracting archive
  - Installing phpunit/php-file-iterator (2.0.3): Extracting archive
  - Installing theseer/tokenizer (1.2.0): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (1.0.2): Extracting archive
  - Installing phpunit/php-code-coverage (7.0.14): Extracting archive
  - Installing doctrine/instantiator (1.4.0): Extracting archive
  - Installing phpspec/prophecy (1.12.1): Extracting archive
  - Installing phar-io/version (3.0.3): Extracting archive
  - Installing phar-io/manifest (2.0.1): Extracting archive
  - Installing myclabs/deep-copy (1.10.2): Extracting archive
  - Installing phpunit/phpunit (8.5.13): Extracting archive
  - Installing symfony/var-dumper (v5.2.0): Extracting archive
  - Installing nikic/php-parser (v4.10.3): Extracting archive
  - Installing dnoegel/php-xdg-base-dir (v0.1.1): Extracting archive
  - Installing psy/psysh (v0.10.5): Extracting archive
21 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
46 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../cakephp/cakephp-codesniffer,../../slevomat/coding-standard
> App\Console\Installer::postInstall
Created `config/app_local.php` file
Created `/Users/home/Documents/Dev/cake_app/logs` directory
Created `/Users/home/Documents/Dev/cake_app/tmp/cache/views` directory
Set Folder Permissions ? (Default to Y) [Y,n]? Y   
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/cache
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/cache/models
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/cache/persistent
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/cache/views
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/sessions
Permissions set on /Users/home/Documents/Dev/cake_app/tmp/tests
Permissions set on /Users/home/Documents/Dev/cake_app/tmp
Permissions set on /Users/home/Documents/Dev/cake_app/logs
Updated Security.salt value in config/app_local.php

構築できました。あとは起動できるか確認するだけです。

動作確認

内蔵の開発サーバーを起動して、ちゃんとアクセスできるか確認します。

~/D/D/cake_app ❯❯❯ bin/cake server

Welcome to CakePHP v4.1.6 Console
-------------------------------------------------------------------------------
App : src
Path: /Users/home/Documents/Dev/cake_app/src/
DocumentRoot: /Users/home/Documents/Dev/cake_app/webroot
Ini Path: 
-------------------------------------------------------------------------------
built-in server is running in http://localhost:8765/

起動はできてるっぽいですね。localhostにアクセスして画面を確認してみます。

大丈夫そうですね。これで開発に入れます。

コメント

タイトルとURLをコピーしました