スポンサーリンク

AWS(CentOS7)でCakePHP3.6の環境構築時,Composerのハマり所の対処法


AWS (Amazon EC2)上で,LinuxサーバにCakePHP3.6をセットアップして動かす。

ハマるツボは,プロジェクトを作成するときのComposerの動作。

  • Apache(httpd)をインストール済み
  • PHPをインストール済み(phpinfo()が動く)
  • ComposerでCakePHPプロジェクトを作成 ←ここが難しい。

正しい手順

yumでGitをインストール。(コマンドは省略)

PHPに必要なXML関係のライブラリの依存関係を解決:

composer global require "squizlabs/php_codesniffer=*"
yum -y install --enablerepo=remi,epel,remi-php70 php-xml
composer global  require "squizlabs/php_codesniffer=*"


/var/www/htmlにて,hogeという名前のCakePHPプロジェクトを作成:

composer self-update && composer create-project --prefer-dist cakephp/app hoge

httpd.confにて公開設定:

  DocumentRoot /var/www/html
  <Directory /var/www/html/hoge>
    Options FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow from all
  </Directory>

プロジェクトのルートフォルダにて,ログとキャッシュのパーミッションを変更:

chmod 777 logs
chmod 666 logs/empty
chmod 666 logs/error.log
chmod -R 777 tmp

これでCakePHPのトップ画面が正しく表示される。


以下は,正しい手順にたどり着くまでの迷走の記録。

ComposerでCakePHPのプロジェクトを作成しようとして怒られる

phpからcomposerを起動して,dir_fugaという名前のアプリを作成しようとするとエラー

[root@ip-10-0-0-999 hoge]# php /usr/local/bin/composer create-project --prefer-dist cakephp/app "dir_fuga"
Installing cakephp/app (3.6.2)
    Failed to download cakephp/app from dist: The zip extension and unzip command are both missing, skipping.
Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
    Now trying to download from source
  - Installing cakephp/app (3.6.2): Cloning e9db6ec681


  [RuntimeException]
  Failed to clone https://github.com/cakephp/app.git, git was not found, chec
  k that it is installed and in your PATH env.

  sh: git: command not found


create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]


yumでGitをインストールしてからやり直し。

同じコマンドをもう一度叩く

ext-simplexmlが無いと怒られる

[root@ip-10-0-0-999 hoge]# php /usr/local/bin/composer create-project --prefer-dist cakephp/app "dir_fuga"
Installing cakephp/app (3.6.2)
  - Installing cakephp/app (3.6.2): Downloading (100%)
Created project in dir_fuga
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-codesniffer 3.0.0 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0].
    - cakephp/cakephp-codesniffer 3.0.1 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0].
    - cakephp/cakephp-codesniffer 3.0.2 requires squizlabs/php_codesniffer ~3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2].
    - cakephp/cakephp-codesniffer 3.0.3 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0].
    - cakephp/cakephp-codesniffer 3.0.4 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0].
    - cakephp/cakephp-codesniffer 3.0.5 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.3.0].
    - squizlabs/php_codesniffer 3.3.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.2.3 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.2.2 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.2.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.2.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.1.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.1.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.2 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - Installation request for cakephp/cakephp-codesniffer ^3.0 -> satisfiable by cakephp/cakephp-codesniffer[3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-intl.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-mbstring.ini
    - /etc/php.d/20-mysqlnd.ini
    - /etc/php.d/20-pdo.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-sqlite3.ini
    - /etc/php.d/20-tokenizer.ini
    - /etc/php.d/30-mysqli.ini
    - /etc/php.d/30-pdo_mysql.ini
    - /etc/php.d/30-pdo_sqlite.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

ext-simplexmlというものはない。

存在しないものを要求されるのは困る。


下記のコマンドを実行しても変化なし。

composer self-update && composer create-project --prefer-dist cakephp/app hoge

だめ


php_codesnifferの依存を解決(2.2.0)

[root@ip-10-0-0-999 dir_fuga]# composer global require "squizlabs/php_codesniffer=*"
Changed current directory to /root/.config/composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing squizlabs/php_codesniffer (2.2.0): Downloading (100%)
Writing lock file
Generating autoload files
[root@ip-10-0-0-999 dir_fuga]#

OK


php-xmlの依存を解決

[root@ip-10-0-0-999 dir_fuga]# yum -y install --enablerepo=remi,epel,remi-php70 php-xml
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * remi: ftp.riken.jp
 * remi-php70: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package php-xml.x86_64 0:7.0.30-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package        Arch          Version                   Repository         Size
================================================================================
Installing:
 php-xml        x86_64        7.0.30-1.el7.remi         remi-php70        207 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 207 k
Installed size: 854 k
Downloading packages:
php-xml-7.0.30-1.el7.remi.x86_64.rpm                       | 207 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-xml-7.0.30-1.el7.remi.x86_64                             1/1
  Verifying  : php-xml-7.0.30-1.el7.remi.x86_64                             1/1

Installed:
  php-xml.x86_64 0:7.0.30-1.el7.remi

Complete!

OK

php_codesnifferをアップデート(3.3.0)

[root@ip-10-0-0-999 dir_fuga]#  composer global  require "squizlabs/php_codesniffer=*"
Changed current directory to /root/.config/composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating squizlabs/php_codesniffer (2.2.0 => 3.3.0): Downloading (100%)     Writing lock file
Generating autoload files
[root@ip-10-0-0-999 dir_fuga]#

OK

ComposerでCakePHPプロジェクトを作成

dir_fugaというフォルダ内に,hogeという名前のCakePHPプロジェクトを作成する。

[root@ip-10-0-0-999 dir_fuga]# composer self-update && composer create-project --prefer-dist cakephp/app hoge
You are already using composer version 1.6.5 (stable channel).
Installing cakephp/app (3.6.2)
  - Installing cakephp/app (3.6.2): Loading from cache
Created project in hoge
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 47 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.7.2): Downloading (100%)
  - Installing psr/log (1.0.2): Downloading (100%)
  - Installing cakephp/chronos (1.2.1): Downloading (100%)
  - Installing cakephp/cakephp (3.6.6): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.8.0): Downloading (100%)
  - Installing symfony/yaml (v3.4.12): Downloading (100%)
  - Installing symfony/debug (v3.4.12): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.8.0): Downloading (100%)
  - Installing symfony/console (v3.4.12): Downloading (100%)
  - Installing symfony/filesystem (v3.4.12): Downloading (100%)
  - Installing symfony/config (v3.4.12): Downloading (100%)
  - Installing robmorgan/phinx (v0.8.1): Downloading (100%)
  - Installing cakephp/migrations (1.8.1): Downloading (100%)
  - Installing m1/env (2.1.2): Downloading (100%)
  - Installing josegonzalez/dotenv (3.2.0): Downloading (100%)
  - Installing mobiledetect/mobiledetectlib (2.8.32): Downloading (100%)          - Installing twig/twig (v1.35.3): 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.1): Downloading (100%)         - Installing wyrihaximus/twig-view (4.3.4): Downloading (100%)
  - Installing cakephp/bake (1.8.1): Downloading (100%)
  - Installing squizlabs/php_codesniffer (3.3.0): Loading from cache
  - Installing cakephp/cakephp-codesniffer (3.0.5): Downloading (100%)
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)
  - Installing symfony/process (v3.4.12): Downloading (100%)
  - Installing symfony/finder (v3.4.12): Downloading (100%)
  - Installing seld/phar-utils (1.0.1): Downloading (100%)
  - Installing seld/jsonlint (1.7.1): Downloading (100%)
  - Installing seld/cli-prompt (1.0.3): Downloading (100%)
  - Installing justinrainbow/json-schema (5.2.7): Downloading (100%)
  - Installing composer/spdx-licenses (1.4.0): Downloading (100%)
  - Installing composer/semver (1.4.2): Downloading (100%)
  - Installing composer/ca-bundle (1.1.1): Downloading (100%)
  - Installing composer/composer (1.6.5): Downloading (100%)
  - Installing cakephp/debug_kit (3.16.3): Downloading (100%)
  - Installing symfony/var-dumper (v3.4.12): Downloading (100%)
  - Installing nikic/php-parser (v4.0.2): 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 psy/psysh (v0.9.6): 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/app suggests installing phpunit/phpunit (Allows automated tests to be run without system-wide install.)
cakephp/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
symfony/console suggests installing psr/log-implementation (For using the console logger)
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)
composer/composer suggests installing ext-zip (Enabling the zip extension allows you to unzip archives)
symfony/var-dumper suggests installing ext-symfony_debug ()
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 `/var/www/html/dir_fuga/hoge/tmp/cache/views` directory
Set Folder Permissions ? (Default to Y) [Y,n]? y
Permissions set on /var/www/html/dir_fuga/hoge/tmp/cache
Permissions set on /var/www/html/dir_fuga/hoge/tmp/cache/models
Permissions set on /var/www/html/dir_fuga/hoge/tmp/cache/persistent
Permissions set on /var/www/html/dir_fuga/hoge/tmp/cache/views
Permissions set on /var/www/html/dir_fuga/hoge/tmp/sessions
Permissions set on /var/www/html/dir_fuga/hoge/tmp/tests
Permissions set on /var/www/html/dir_fuga/hoge/tmp
Permissions set on /var/www/html/dir_fuga/hoge/logs
Updated Security.salt value in config/app.php
[root@ip-10-0-0-999 dir_fuga]#
[root@ip-10-0-0-999 dir_fuga]# ll
total 4
drwxr-xr-x. 12 root root 4096 Jun 27 16:32 hoge

ようやくOK。CakePHPプロジェクトが作成された。

主な手順
https://qiita.com/h-adachi/items/668fe6ede360bddb2c3e

エラー解決に役立ったURL
http://nyameji.hatenablog.com/entry/2017/11/19/234331


CakePHPのトップ画面がやっと出せた
https://***.example.com/dir_fuga/hoge/


Apacheの設定を変更

SELINUXを無効化

/var/www/htmlでComposerによるプロジェクト作成をやり直し。



/etc\httpd/conf/httpd.conf

#<VirtualHost *:80>
  DocumentRoot /var/www/html
  <Directory /var/www/html/hoge>
    Options FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow from all
  </Directory>
#</VirtualHost>

ログとキャッシュのパーミッションを変更

-rw-rw-r--. 1 root root   0 Jun 27 17:31 empty
-rw-rw-r--. 1 root root 588 Jun 27 17:31 error.log
[root@ip-10-0-0-999 logs]# chmod 666 error.log


[root@ip-10-0-0-999 hoge]# chmod 777 logs
[root@ip-10-0-0-999 hoge]# chmod 666 logs/empty
[root@ip-10-0-0-999 hoge]# chmod 666 logs/error.log
[root@ip-10-0-0-999 hoge]# chmod -R 777 tmp


これで https://***.example.com/hoge/ で

PHPエラー無しでCAKEのデフォルト画面がようやく出る。