CakePHP3の開発用サーバーを動かす
とあるきっかけがあり、CakePHP3を触ることにしました。
早速、公式ドキュメントに載っているブックマークチュートリアルを写経するところから始めようと思い、
CakePHPのインストールを行うために、下記コマンドを実行してみました。
$ php composer.phar create-project --prefer-dist cakephp/app bookmarker
しばらく待ってみたところ、
$ php composer.phar create-project --prefer-dist cakephp/app bookmarker Installing cakephp/app (3.1.1) - Installing cakephp/app (3.1.1) Loading from cache Created project in bookmarker Loading composer repositories with package information Installing dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - cakephp/cakephp 3.2.x-dev requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.2 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.1 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.0-beta2 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.0-beta requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.0-RC1 requires ext-intl * -> the requested PHP extension intl is missing from your system. - cakephp/cakephp 3.1.0 requires ext-intl * -> the requested PHP extension intl is missing from your system. - Installation request for cakephp/cakephp ~3.1 -> satisfiable by cakephp/cakephp[3.1.0, 3.1.0-RC1, 3.1.0-beta, 3.1.0-beta2, 3.1.1, 3.1.2, 3.2.x-dev].
何やらエラーが出ていました。
しかし、「Created project in bookmarker」と出ていますし、ディレクトリ構成もチュートリアルに掲載されているものと一致していたので、
$ bin/cake server
こちらのコマンドを実行してとりあえず開発サーバーを起動してみようと思います。
$ bin/cake server PHP Warning: require(/path/to/bookmarker/vendor/autoload.php): failed to open stream: No such file or directory in /path/to/bookmarker/config/bootstrap.php on line 23 PHP Stack trace: PHP 1. {main}() /path/to/bookmarker/bin/cake.php:0 PHP 2. include() /path/to/bookmarker/bin/cake.php:31 PHP Fatal error: require(): Failed opening required '/path/to/bookmarker/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /path/to/bookmarker/config/bootstrap.php on line 23 PHP Stack trace: PHP 1. {main}() /path/to/bookmarker/bin/cake.php:0 PHP 2. include() /path/to/bookmarker/bin/cake.php:31
世間はそんなに甘くはありませんでした。。。
※上記エラーメッセージのbookmakerディレクトリより上位ディレクトリの絶対パスは書き換えています。
こけた原因
エラーメッセージを見てみると、どうもvendor下にあるべきファイルが無くて怒られているようです。
しかし、真の原因はインストール時に叩いたコマンドのエラーメッセージに書かれている。
the requested PHP extension intl is missing from your system.
ということ。
つまり、php.intlが入って無くてインストール出来なかったという事実が判明しました。
対策
yum install php-pear
足りないパッケージを経て、
yum install -y glibc-devel.x86_64
下記コマンドを叩いてphp.intlをインストールします。
yum install php-intl
php.intlのインストールが終わったところで、先ほどbookmarkerディレクトリに作成したCakeのスケルトンを削除し、
もう一度、作り直してみます。
$ php composer.phar create-project --prefer-dist cakephp/app bookmarker Installing cakephp/app (3.1.1) - Installing cakephp/app (3.1.1) Loading from cache Created project in bookmarker Loading composer repositories with package information Installing dependencies (including require-dev) - Installing aura/installer-default (1.0.0) Downloading: 100% - Installing cakephp/plugin-installer (0.0.12) Downloading: 100% - Installing psr/log (1.0.0) Downloading: 100% - Installing aura/intl (1.1.1) Downloading: 100% - Installing ircmaxell/password-compat (v1.0.4) Downloading: 100% - Installing nesbot/carbon (1.13.0) Downloading: 100% - Installing cakephp/cakephp (3.1.3) Downloading: 100% - Installing cakephp/bake (1.1.0) Downloading: 100% - Installing mobiledetect/mobiledetectlib (2.8.17) Downloading: 100% - Installing symfony/yaml (v2.7.5) Downloading: 100% - Installing symfony/filesystem (v2.7.5) Downloading: 100% - Installing symfony/config (v2.7.5) Downloading: 100% - Installing symfony/console (v2.7.5) Downloading: 100% - Installing robmorgan/phinx (dev-master 43313ad) Downloading: 100% - Installing cakephp/migrations (1.4) 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 (v1.4.1) Downloading: 100% - Installing symfony/var-dumper (v2.7.5) Downloading: 100% - Installing psy/psysh (v0.5.2) Downloading: 100% - Installing jdorn/sql-formatter (v1.2.17) Downloading: 100% - Installing cakephp/debug_kit (3.2.2) Downloading: 100% 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.) 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 /path/to/bookmarker/tmp/cache Permissions set on /path/to/bookmarker/tmp/cache/models Permissions set on /path/to/bookmarker/tmp/cache/persistent Permissions set on /path/to/bookmarker/tmp/cache/views Permissions set on /path/to/bookmarker/tmp/sessions Permissions set on /path/to/bookmarker/tmp/tests Permissions set on /path/to/bookmarker/tmp Permissions set on /path/to/bookmarker/logs Updated Security.salt value in config/app.php
明らかに先ほどとは出来具合が違います。
そこで、開発用サーバーを起動してみます。
$ bin/cake server Welcome to CakePHP v3.1.3 Console --------------------------------------------------------------- App : src Path: /path/to/bookmarker/src/ DocumentRoot: /path/to/bookmarker/webroot --------------------------------------------------------------- built-in server is running in http://localhost:8765/ You can exit with `CTRL-C`
無事、開発用サーバーが起動しました。
※参考
https://secure.nanako-net.info/redmine/projects/know-how/wiki/Php-pear#モジュールのインストール
CakePHP3.0をインストールしてみる(自分用めもめも - Qiita