CakePHP3をWindows環境にインストールして動作させてみたいと思います。
PC環境
今回CakePHP3をインストールする環境になります。
- Windows10
- xammp(v.3.2.2)
- PHP(v7.1.1)
- Composer(v1.4.2)
インストールするにはComposerが必要
CakePHP3をインストールするには、Composerを使ってインストールすることになっています。
ただ、昔のようにZipファイルをダウンロードして設置する方法も可能で、設置方法は下記記事にまとめてあります。
CakePHP3をインストール
ドキュメントルートを把握する
XAMMPを使う場合、ドキュメントルートは初期設定のままであれば下記になります。なので、ドキュメントルート配下にCakePHP3をインストールする必要があります。
1 | C:\xampp\htdocs |
もし、ご自身のドキュメントルートがわからない場合は、設定ファイルを確認しましょう。
C:\xampp\apache\conf\httpd.conf
※httpd.conf内を「DocumentRoot」で検索かけるとヒットします。
1 2 3 4 5 6 | # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "C:/xampp/htdocs" |
インストール作業
CakePHP3をインストールしていきたいと思います。
CakePHP3をインストールするフォルダを先に作成しておきます。今回は、「dev-cake」というフォルダを作成して入れたいと思います。
1 2 3 4 5 | #ドキュメントルートに移動 cd C:\xampp\htdocs #プロジェクトフォルダを作成 mkdir dev-cake |
プロジェクトフォルダが出来たら、作成したフォルダを指定してインストールします。
ちなみに作成したフォルダの中身は空の状態にしておいてください。ファイルが入っているとインストールできません。
1 2 | #cakephp3をインストール composer create-project --prefer-dist -s dev cakephp/app dev-cake |
数分でインストールが完了しますが、最後にY/Nで聞かれますので、「Y」を入力してEnterを押します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | C:\xampp\htdocs>composer create-project --prefer-dist -s dev cakephp/app dev-cake Installing cakephp/app (dev-master e1a10feea808d2caa9c4c30518cbca5bb1b78773) - Installing cakephp/app (dev-master master): Loading from cache Created project in dev-cake Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 46 installs, 0 updates, 0 removals - Installing cakephp/plugin-installer (1.1.0): Loading from cache - Installing aura/intl (3.0.0): Downloading (100%) - Installing psr/http-message (1.0.1): Downloading (100%) - Installing zendframework/zend-diactoros (1.6.1): Loading from cache - Installing psr/log (1.0.2): Downloading (100%) - Installing cakephp/chronos (1.1.3): Loading from cache - Installing cakephp/cakephp (3.5.10): Loading from cache - Installing symfony/polyfill-mbstring (v1.6.0): Loading from cache - Installing symfony/yaml (v3.4.2): Loading from cache - Installing symfony/debug (v3.4.2): Loading from cache - Installing symfony/console (v3.4.2): Loading from cache - Installing symfony/filesystem (v3.4.2): Loading from cache - Installing symfony/config (v3.4.2): Loading from cache - Installing robmorgan/phinx (v0.8.1): Loading from cache - Installing cakephp/migrations (1.7.2): Loading from cache - Installing m1/env (2.1.0): Loading from cache - Installing josegonzalez/dotenv (2.1.0): Loading from cache - Installing mobiledetect/mobiledetectlib (2.8.30): Loading from cache - Installing twig/twig (v1.35.0): Loading from cache - Installing umpirsky/twig-php-function (v0.1): Loading from cache - Installing jasny/twig-extensions (v1.2.0): Loading from cache - Installing asm89/twig-cache-extension (1.3.2): Loading from cache - Installing aptoma/twig-markdown (2.0.0): Downloading (100%) - Installing ajgl/breakpoint-twig-extension (0.3.1): Downloading (connecting..Downloading (100%) - Installing wyrihaximus/twig-view (4.3.0): Downloading (100%) - Installing cakephp/bake (1.6.0): Downloading (100%) - Installing squizlabs/php_codesniffer (3.2.2): Downloading (100%) - Installing cakephp/cakephp-codesniffer (3.0.3): Downloading (100%) - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%) - Installing symfony/process (v3.4.2): Downloading (100%) - Installing symfony/finder (v3.4.2): Downloading (100%) - Installing seld/phar-utils (1.0.1): Downloading (100%) - Installing seld/jsonlint (1.6.2): Downloading (100%) - Installing seld/cli-prompt (1.0.3): Downloading (100%) - Installing justinrainbow/json-schema (5.2.6): Downloading (100%) - Installing composer/spdx-licenses (1.1.6): Downloading (100%) - Installing composer/semver (1.4.2): Downloading (100%) - Installing composer/ca-bundle (1.1.0): Downloading (100%) - Installing composer/composer (1.5.6): Downloading (100%) - Installing cakephp/debug_kit (3.11.4): Downloading (100%) - Installing jakub-onderka/php-console-color (0.1): Downloading (connecting...Downloading (100%) - Installing jakub-onderka/php-console-highlighter (v0.3.2): Downloading (connDownloading (100%) - Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%) - Installing nikic/php-parser (v3.1.3): Downloading (100%) - Installing symfony/var-dumper (v3.4.2): Downloading (100%) - Installing psy/psysh (v0.8.17): Downloading (100%) cakephp/app suggests installing phpunit/phpunit (Allows automated tests to be run without system-wide install.) 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/console suggests installing symfony/event-dispatcher () symfony/console suggests installing symfony/lock () m1/env suggests installing m1/vars (For loading of configs) 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) cakephp/debug_kit suggests installing ext-sqlite (DebugKit needs to store panel data in a database. SQLite is simple and easy to use.) 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-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.) Writing lock file Generating autoload files > Cake\Composer\Installer\PluginInstaller::postAutoloadDump > App\Console\Installer::postInstall Created `config/app.php` file Created `C:\xampp\htdocs\dev-cake/tmp/cache/views` directory Set Folder Permissions ? (Default to Y) [Y,n]? |
完了したらWEBブラウザからアクセスします。
URL:http://localhost/dev-cake
WEBブラウザにアクセスすると下記のようなエラーが表示されます。
Fatal error: You must enable the intl extension to use CakePHP. in C:\xampp\htdocs\dev-cake\config\requirements.php on line 31
このエラーが表示されたら、php.iniファイルの「php_intl.dll」を有効にしてあげる必要があります。
※先頭にあるセミコロン「;」を削除してください。
C:\xampp\php\php.ini
1 | extension=php_intl.dll |
修正が終わったら、XAMMPのApacheを再起動します。
※再起動をしないと修正した内容が読み込まれないため必ず再起動してください。
再起動が終わったら、再度WEBブラウザからアクセスします。

エラーもなく正常に表示されていれば、インストール完了です。
まとめ
CakPHP3のインストールは、Composerを採用したこともあって簡単にインストールできるようになっています。
「php_intl.dll」を有効にしないといけいところを見落としがちなので注意しましょう。
コメントを残す