PHP

CakePHP3のインストールとWelcomeページ表示

cakephp
o_wani
この記事は作成から7年以上経過しているため、内容が古くなっている可能性があります。

Vagrantを使った環境にCakePHP3をインストールしてみた。

環境

  • CentOS7
  • PHP7.0.14

Composerのインストール

公式サイト通り下記コマンド実行。

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"

Composerにパスを通す

composerコマンドが使えるようにパスを通す。

$ sudo mv composer.phar /usr/local/bin/composer

CakePHPプロジェクトを作成

CakePHPのインストールとプロジェクトの作成をcomposerで実施。
プロジェクト名:my_app_name

$ composer self-update && composer create-project --prefer-dist cakephp/app my_app_name
You are already using composer version 1.3.1 (stable channel).
Installing cakephp/app (3.3.5)
  - Installing cakephp/app (3.3.5) Downloading: 100%         
Created project in my_app_name
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.3.9 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.3.8 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.3.7 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.3.6 requires ext-intl * -> the requested PHP extension intl is missing from your system.
    - cakephp/cakephp 3.3.5 requires ext-intl * -> the requested PHP extension intl is missing from your system.
...
...

エラーが出る。
requires ext-intl

エラーの解決

intl インストール。

$ sudo yum install php70w-intl

または

$ sudo yum install php-intl

再度プロジェクト作成にトライ

 $ composer self-update && composer create-project --prefer-dist cakephp/app my_app_name
You are already using composer version 1.3.1 (stable channel).
Installing cakephp/app (3.3.5)
  - Installing cakephp/app (3.3.5) Loading from cache
Created project in my_app_name
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 26 installs, 0 updates, 0 removals
  - Installing aura/installer-default (1.0.0) Downloading: 100%         
  - Installing cakephp/plugin-installer (0.0.15) Downloading: 100%         
  - Installing mobiledetect/mobiledetectlib (2.8.24) Downloading: 100%         
  - Installing psr/http-message (1.0.1) Downloading: 100%         
  - Installing zendframework/zend-diactoros (1.3.8) Downloading: 100%         
  - Installing aura/intl (1.1.1) Downloading: 100%         
  - Installing cakephp/chronos (1.0.4) Downloading: 100%         
  - Installing psr/log (1.0.2) Downloading: 100%         
  - Installing cakephp/cakephp (3.3.11) Downloading: 100%         
  - Installing symfony/yaml (v3.2.1) Downloading: 100%         
  - Installing symfony/debug (v3.2.1) Downloading: 100%         
  - Installing symfony/polyfill-mbstring (v1.3.0) Downloading: 100%         
  - Installing symfony/console (v3.2.1) Downloading: 100%         
  - Installing symfony/filesystem (v3.2.1) Downloading: 100%         
  - Installing symfony/config (v3.2.1) 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.2) Downloading: 100%         
  - Installing symfony/var-dumper (v3.2.1) Downloading: 100%         
  - Installing psy/psysh (v0.8.0) Downloading: 100%         
  - Installing jdorn/sql-formatter (v1.2.17) Downloading: 100%         
  - Installing cakephp/debug_kit (3.5.0) Downloading: 100%         
  - Installing cakephp/bake (1.2.11) 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.)
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/process ()
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 /home/vagrant/cakephp/my_app_name/tmp/cache
Permissions set on /home/vagrant/cakephp/my_app_name/tmp/cache/models
Permissions set on /home/vagrant/cakephp/my_app_name/tmp/cache/persistent
Permissions set on /home/vagrant/cakephp/my_app_name/tmp/cache/views
Permissions set on /home/vagrant/cakephp/my_app_name/tmp/sessions
Permissions set on /home/vagrant/cakephp/my_app_name/tmp/tests
Permissions set on /home/vagrant/cakephp/my_app_name/tmp
Permissions set on /home/vagrant/cakephp/my_app_name/logs
Updated Security.salt value in config/app.php

無事インストールされた。

Welcomeページ表示

Apacheのサーバを設定して表示した。
今回の場合my_app_name/webrootDocumentRootである。

Apacheの設定

ちなみにVagrant環境でのApacheの設定は、以下。

<VirtualHost *:8080>
ServerName cakephp.local
DocumentRoot /home/vagrant/cakephp/my_app_name/webroot
<Directory /home/vagrant/cakephp/my_app_name/webroot>
    AllowOverride All
    Require all granted
    Options -MultiViews
    EnableSendfile off
</Directory>
</VirtualHost>

表示

Alt text

赤が目立つページでした。

参考
インストール

STAFF
o_wani
o_wani
スタッフ
大学卒業後、15年間WEB業界で働く。現在はマネジメントに従事していますが、ChatGPTの登場に触発され、このブログを再開。AIをパートナーに、自分で手を動かして実装する楽しさと喜びを再発見中。時代が変わりつつある中でも、陳腐化しない情報発信も目指しています。
記事URLをコピーしました