3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Windows7】XAMPPでCakePHP 3.7の動作環境を構築する

Posted at

はじめに

CakePHP3が提供している機能や気になっているライブラリを試すために、自宅のPCにCakePHP3の動作環境を構築することにしました。
ただ、ミドルウェアなど諸々の導入にあまり時間をかけたくなかったので、今回はXAMPPを利用して動作環境を構築します。

達成目標

1.XAMPPをインストールする。
2.ComposerでCakePHP 3.7をインストールし、正常に動作する環境を構築する。

動作環境

バージョン
OS Windows7 (64bit)

環境構築手順

XAMPPインストール手順

インストーラ入手

Apache Friendsにアクセスし、「Windows 向け XAMPP」をクリックしてインストーラをダウンロード。
なお、今回ダウンロードしたインストーラは「xampp-windows-x64-7.3.5-0-VC15-installer.exe」ですが、別バージョンをダウンロードした場合や、ダウンロード時期によって変わることがある点に注意してください。
SnapCrab_NoName_2019-5-11_17-47-0_No-00.png
SnapCrab_xampp-windows-x64-735-0-VC15-installerexe を開く_2019-5-11_17-47-18_No-00.png

インストール

ダウンロードしたインストーラを起動し、XAMPPをインストール。
インストール内容については各環境に準拠してください。
SnapCrab_Setup_2019-5-11_18-13-24_No-00.png
SnapCrab_Setup_2019-5-11_18-13-37_No-00.png
SnapCrab_Setup_2019-5-11_18-14-0_No-00.png
SnapCrab_Setup_2019-5-11_18-14-15_No-00.png
SnapCrab_Setup_2019-5-11_18-14-39_No-00.png
SnapCrab_Setup_2019-5-11_18-14-51_No-00.png
SnapCrab_Setup_2019-5-11_18-23-1_No-00.png

動作確認

XAMPPコントロールパネルを起動し、ApacheとMySQLが正常に動作するか確認。
SnapCrab_Language_2019-5-11_18-23-18_No-00.png
SnapCrab_XAMPP Control Panel v323   [ Compiled Mar 7th 2019 ]_2019-5-11_18-27-37_No-00.png
SnapCrab_NoName_2019-5-11_18-26-49_No-00.png
SnapCrab_NoName_2019-5-11_18-27-49_No-00.png

Composerインストール手順

インストーラ入手

コチラから、Composerのインストーラをダウンロード。
SnapCrab_NoName_2019-5-12_9-33-26_No-00.png
SnapCrab_Composer-Setupexe を開く_2019-5-12_9-33-58_No-00.png

インストール

ダウンロードしたインストーラを起動し、Composerをインストール。
インストール内容については各環境に準拠してください。
SnapCrab_Composer Setup_2019-5-12_9-35-51_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-36-3_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-36-13_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-36-48_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-37-1_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-37-19_No-00.png
SnapCrab_Composer Setup_2019-5-12_9-37-53_No-00.png

動作確認

git-bash
$ composer -V
Composer version 1.8.5 2019-04-09 17:46:47

CakePHPインストール手順

前準備

Cookbookを参考に、CakePHP 3.7のシステム要件を満たすようにPHP拡張を有効化する。

git-bash
$ vi /c/xampp/php/php.ini
911行目付近の「;extension=intl」のコメントアウトを解除

インストール

なお、Apacheのドキュメントルートは変更していないことを仮定しています。

git-bash
$ cd /c/xampp/htdocs

$ composer self-update && composer create-project --prefer-dist cakephp/app cakephp3
You are already using composer version 1.8.5 (stable channel).
Installing cakephp/app (3.7.1)
  - Installing cakephp/app (3.7.1): Loading from cache
Created project in cakephp3
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 77 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.1.0): Downloading (100%)
  - Installing aura/intl (3.0.0): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing zendframework/zend-diactoros (1.8.6): Downloading (100%)
  - Installing psr/simple-cache (1.0.1): Downloading (100%)
  - Installing psr/log (1.1.0): Downloading (100%)
  - Installing cakephp/chronos (1.2.5): Downloading (100%)
  - Installing cakephp/cakephp (3.7.7): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.11.0): Downloading (100%)
  - Installing symfony/yaml (v4.2.8): Downloading (100%)
  - Installing symfony/filesystem (v4.2.8): Downloading (100%)
  - Installing symfony/config (v4.2.8): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.11.0): Downloading (100%)
  - Installing symfony/contracts (v1.1.0): Downloading (100%)
  - Installing symfony/console (v4.2.8): Downloading (100%)
  - Installing robmorgan/phinx (0.10.7): Downloading (100%)
  - Installing cakephp/migrations (2.1.1): Downloading (100%)
  - Installing mobiledetect/mobiledetectlib (2.8.33): Downloading (100%)
  - Installing twig/twig (v1.40.1): Downloading (100%)
  - Installing umpirsky/twig-php-function (v0.1): Downloading (100%)
  - Installing jasny/twig-extensions (v1.2.0): Downloading (100%)
  - Installing asm89/twig-cache-extension (1.3.2): Downloading (100%)
  - Installing aptoma/twig-markdown (2.0.0): Downloading (100%)
  - Installing ajgl/breakpoint-twig-extension (0.3.4): Downloading (100%)
  - Installing wyrihaximus/twig-view (4.3.8): Downloading (100%)
  - Installing cakephp/bake (1.9.6): Downloading (100%)
  - Installing squizlabs/php_codesniffer (3.4.2): Downloading (100%)
  - Installing cakephp/cakephp-codesniffer (3.1.1): Downloading (100%)
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)
  - Installing symfony/process (v4.2.8): Downloading (100%)
  - Installing symfony/finder (v4.2.8): Downloading (100%)
  - Installing seld/phar-utils (1.0.1): Downloading (100%)
  - Installing seld/jsonlint (1.7.1): Downloading (100%)
  - Installing justinrainbow/json-schema (5.2.8): Downloading (100%)
  - Installing composer/xdebug-handler (1.3.2): Downloading (100%)
  - Installing composer/spdx-licenses (1.5.1): Downloading (100%)
  - Installing composer/semver (1.5.0): Downloading (100%)
  - Installing composer/ca-bundle (1.1.4): Downloading (100%)
  - Installing composer/composer (1.8.5): Downloading (100%)
  - Installing cakephp/debug_kit (3.18.0): Downloading (100%)
  - Installing m1/env (2.1.2): Downloading (100%)
  - Installing josegonzalez/dotenv (3.2.0): Downloading (100%)
  - Installing sebastian/version (2.0.1): Downloading (100%)
  - Installing sebastian/resource-operations (1.0.0): Downloading (100%)
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)
  - Installing sebastian/object-reflector (1.1.1): Downloading (100%)
  - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)
  - Installing sebastian/global-state (2.0.0): Downloading (100%)
  - Installing sebastian/exporter (3.1.0): Downloading (100%)
  - Installing sebastian/environment (3.1.0): Downloading (100%)
  - Installing sebastian/diff (2.0.1): Downloading (100%)
  - Installing sebastian/comparator (2.1.3): Downloading (100%)
  - Installing doctrine/instantiator (1.2.0): Downloading (100%)
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)
  - Installing phpunit/phpunit-mock-objects (5.0.10): Downloading (100%)
  - Installing phpunit/php-timer (1.0.9): Downloading (100%)
  - Installing phpunit/php-file-iterator (1.4.5): Downloading (100%)
  - Installing theseer/tokenizer (1.1.2): Downloading (100%)
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (100%)
  - Installing phpunit/php-token-stream (2.0.2): Downloading (100%)
  - Installing phpunit/php-code-coverage (5.3.2): Downloading (100%)
  - Installing webmozart/assert (1.4.0): Downloading (100%)
  - Installing phpdocumentor/reflection-common (1.0.1): Downloading (100%)
  - Installing phpdocumentor/type-resolver (0.4.0): Downloading (100%)
  - Installing phpdocumentor/reflection-docblock (4.3.1): Downloading (100%)
  - Installing phpspec/prophecy (1.8.0): Downloading (100%)
  - Installing phar-io/version (1.0.1): Downloading (100%)
  - Installing phar-io/manifest (1.0.1): Downloading (100%)
  - Installing myclabs/deep-copy (1.9.1): Downloading (100%)
  - Installing phpunit/phpunit (6.5.14): Downloading (100%)
  - Installing jakub-onderka/php-console-color (v0.2): Downloading (100%)
  - Installing jakub-onderka/php-console-highlighter (v0.4): Downloading (100%)
  - Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%)
  - Installing nikic/php-parser (v4.2.1): Downloading (100%)
  - Installing symfony/polyfill-php72 (v1.11.0): Downloading (100%)
  - Installing symfony/var-dumper (v4.2.8): Downloading (100%)
  - Installing psy/psysh (v0.9.9): 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/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/event-dispatcher-implementation
symfony/contracts suggests installing symfony/http-client-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/contracts suggests installing symfony/translation-contracts-implementation
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
asm89/twig-cache-extension suggests installing psr/cache-implementation (To make use of PSR-6 cache implementation via PsrCacheAdapter.)
aptoma/twig-markdown suggests installing michelf/php-markdown (Original Markdown engine with MarkdownExtra.)
aptoma/twig-markdown suggests installing knplabs/github-api (Needed for using GitHub's Markdown engine provided through their API.)
ajgl/breakpoint-twig-extension suggests installing ext-xdebug (The Xdebug extension is required for the breakpoint to work)
ajgl/breakpoint-twig-extension suggests installing symfony/framework-bundle (The framework bundle to integrate the extension into Symfony)
ajgl/breakpoint-twig-extension suggests installing symfony/twig-bundle (The twig bundle to integrate the extension into Symfony)
m1/env suggests installing m1/vars (For loading of configs)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.5.5)
phpunit/phpunit suggests installing phpunit/php-invoker (^1.1)
phpunit/phpunit suggests installing ext-xdebug (*)
psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
psy/psysh suggests installing ext-posix (If you have PCNTL, you'll want the POSIX extension as well.)
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.)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
Created `C:\xampp\htdocs\cakephp3/tmp/cache/views` directory
Set Folder Permissions ? (Default to Y) [Y,n]? y
Updated Security.salt value in config/app.php

動作確認

XAMPPコントロールパネルでApacheを起動し、インストール直後のアプリケーションにアクセス。
SnapCrab_NoName_2019-5-12_11-3-40_No-00.png
データベースへの接続ができていないため、これを修正。

問題解決

phpMyAdminを利用し、接続対象となるデータベースを作成。
phpMyAminを利用したデータベースの作成方法についてはここでは割愛するので、コチラなどを参考にしてください。
SnapCrab_NoName_2019-5-12_11-41-40_No-00.png

アプリケーションのデータベースに関する設定を変更。

cakephp3/config/app.php
<?php
return [

    // 省略

    /**
     * Connection information used by the ORM to connect
     * to your application's datastores.
     *
     * ### Notes
     * - Drivers include Mysql Postgres Sqlite Sqlserver
     *   See vendor\cakephp\cakephp\src\Database\Driver for complete list
     * - Do not use periods in database name - it may lead to error.
     *   See https://github.com/cakephp/cakephp/issues/6471 for details.
     * - 'encoding' is recommended to be set to full UTF-8 4-Byte support.
     *   E.g set it to 'utf8mb4' in MariaDB and MySQL and 'utf8' for any
     *   other RDBMS.
     */
    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            /*
             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
             */
            //'port' => 'non_standard_port_number',
            'username' => '***',  // 作成したユーザ
            'password' => '***',  // 作成したユーザのパスワード
            'database' => '***',  // 作成したデータベース
            /*
             * You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
             */
            //'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false,

            /**
             * Set identifier quoting to true if you are using reserved words or
             * special characters in your table or column names. Enabling this
             * setting will result in queries built using the Query Builder having
             * identifiers quoted when creating SQL. It should be noted that this
             * decreases performance because each query needs to be traversed and
             * manipulated before being executed.
             */
            'quoteIdentifiers' => false,

            /**
             * During development, if using MySQL < 5.6, uncommenting the
             * following line could boost the speed at which schema metadata is
             * fetched from the database. It can also be set directly with the
             * mysql configuration directive 'innodb_stats_on_metadata = 0'
             * which is the recommended value in production environments
             */
            //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],

            'url' => env('DATABASE_URL', null),
        ],

        /**
         * The test connection is used during the test suite.
         */
        'test' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            //'port' => 'non_standard_port_number',
            'username' => '***',  // 作成したユーザ
            'password' => '***',  // 作成したユーザのパスワード
            'database' => '***',  // 作成したデータベース
            //'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'quoteIdentifiers' => false,
            'log' => false,
            //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
            'url' => env('DATABASE_TEST_URL', null),
        ],
    ],

    // 省略
];

再度アプリケーションにアクセス。
SnapCrab_NoName_2019-5-12_11-42-10_No-00.png
先ほどまでエラーだった箇所が解消され、アプリケーションが正常に動作するようになりました。

おわりに

今回構築した環境のバージョン情報は下表の通りです。

名前 バージョン
Apache 2.4.39 (Win64)
MySQL(MariaDB) 15.1 Distrib 10.1.39-MariaDB, for Win64 (AMD64)
Composer 1.8.5
CakePHP 3.7.7

実際にはここからアプリケーションごとに色々と設定を施していく必要がありますが、本題から反れるので割愛させていただきます。

XAMPPを利用すればPHPの動作環境があっという間に整うので、手軽にCakePHP3の動作環境を構築できて良いですね。

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?