Cakephp 3.5 インストール

#Cakephpのインストール

OS: centOS 6.9 

cakephp をインストールを行います。

まずはphp 5.6以降が条件なのでそれをインストールします。

まずはEPELレポジトリーを登録

```
sudo yum install -y epel-release
```

remi レポジトリーを登録
```
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
```

# php 5.6をインストール

```
sudo yum install --enablerepo=remi --enablerepo=remi-php56 -y php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof
```
php intl をインストール

```
sudo yum install --enablerepo=remi --enablerepo=remi-php56 -y php-intl
```

php のtimezoneを指定しします。

```
sudo vim /etc/php.ini 
```

php.ini 左記ファイルを編集し　timezonexをAsia/Tokyoへ変更します。

```

[Date]
 887 ; Defines the default timezone used by the date functions
 888 ; http://php.net/date.timezone
 889 date.timezone = "Asia/Tokyo"


```

Cakephpの公式サイトにはapacheを推奨していたので、

# Apacheをインストール

Apacheをインストールしてみます。

```
sudo yum install -y httpd httpd-devel
```

インストール完了で自動起動をon

```
sudo chkconfig httpd on
```

Apache のconfファイルを編集
```
vim /etc/httpd/conf/httpd.conf
```

```
#ServerName www.example.com:80
ServerName 190.45.23.56:80　IPアドレスとか、ドメインあればドメインとか
```
ポートを指定しておくのが推奨だそうで、

```
#    Options Indexes FollowSymLinks
332      Options Includes ExecCGI FollowSymLinks <- CGI,SSIの許可

339 #    AllowOverride None
 340      AllowOverride All <- .htaccessの許可

498 #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined <- 長すぎるURI(414エラー)はログに記録しない
 499 LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

558 <Directory "/var/www/icons">
 559 #    Options Indexes MultiViews FollowSymLinks
 560     Options MultiViews　<- 　←　iconsディレクトリのファイル一覧を表示しないようにする
 561     AllowOverride None
 562     Order allow,deny
 563     Allow from all
 564 </Directory>

1015 #</VirtualHost>
1016 
1017 TraceEnable off　<- traceメソッドを無効化
1018 

```

上記な感じで設定します。

Apache 構文チェック
```
httpd -t
Syntax OK

```

サーバー起動
```
sudo service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
```

成功しました。
ლ( ╹ε╹ლ)

# iptables ファイアーウォールの確認

ファイアーウォールに穴をあけましょう
80番ポートの穴あけ

```
 sudo vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

```
上記の一行を追加できれば、上記のように22番ポートが開いていたり、ポート的な部分ぽいところに記述するとわかりやすいかと思われます。

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

とか

その後再起動

```
sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

```

開いてるか確認します。

まぁ開いてます、開いてなければ、もう一度iptablesを確認してくダサい。

```
netstat -ant | grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN  
```
とりあえずここでWEBサーバーが起動していて、
ブラウザーで表示できてるか確認します。

ServerNameで指定したさきへブラウザーで叩きます。ペチ！

表示されてればよしです。

# composer インストール

ここでcomposer なるphp 関連のパッケージ管理システムをインスト、
テーマは指揮者だそうで
下記公式サイト
https://getcomposer.org/

```
curl -s https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.5.1) successfully installed to: /var/www/html/composer.phar
Use it: php composer.phar
ls -a
.  ..  composer.phar <- phpの実行形式ファイルjar的な感じだそうでアーカイブ形式だそうです、解凍できます。
sudo mv composer.phar /usr/local/bin/composer　<- bin 直下に移動リネームします。使いやすいので、
composerで呼べます。
```

composer 実行します。

```
composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.5.1 2017-08-09 16:07:22

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about           Shows the short information about Composer.
  archive         Creates an archive of this composer package.
  browse          Opens the package's repository URL or homepage in your browser.
  clear-cache     Clears composer's internal package cache.
  clearcache      Clears composer's internal package cache.
  config          Sets config options.
  create-project  Creates new project from a package into given directory.
  depends         Shows which packages cause the given package to be installed.
  diagnose        Diagnoses the system to identify common errors.
  dump-autoload   Dumps the autoloader.
  dumpautoload    Dumps the autoloader.
  exec            Executes a vendored binary/script.
  global          Allows running commands in the global composer dir ($COMPOSER_HOME).
  help            Displays help for a command
  home            Opens the package's repository URL or homepage in your browser.
  info            Shows information about packages.
  init            Creates a basic composer.json file in current directory.
  install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses        Shows information about licenses of dependencies.
  list            Lists commands
  outdated        Shows a list of installed packages that have updates available, including their latest version.
  prohibits       Shows which packages prevent the given package from being installed.
  remove          Removes a package from the require or require-dev.
  require         Adds required packages to your composer.json and installs them.
  run-script      Runs the scripts defined in composer.json.
  search          Searches for packages.
  self-update     Updates composer.phar to the latest version.
  selfupdate      Updates composer.phar to the latest version.
  show            Shows information about packages.
  status          Shows a list of locally modified packages.
  suggests        Shows package suggestions.
  update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate        Validates a composer.json and composer.lock.
  why             Shows which packages cause the given package to be installed.
  why-not         Shows which packages prevent the given package from being installed.
```

上記のような感じで出力されると、パスが通り、composerで使えます。

# Cakephp インストール

ドキュメントルートのディレクトリーの権限を変更します。

```
sudo chmod composerを実行するユーザーの名前:左記同文 ./html/
```

```
[ami@ik1-316-18051 html]$ composer create-project --prefer-dist cakephp/app ./
Installing cakephp/app (3.5.0)
  - Installing cakephp/app (3.5.0): Downloading (100%)         
Created project in ./
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 39 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.0.0): Downloading (100%)         
  - Installing aura/intl (3.0.0): Downloading (100%)         
  - Installing mobiledetect/mobiledetectlib (2.8.25): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing zendframework/zend-diactoros (1.5.0): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing cakephp/chronos (1.1.2): Downloading (100%)         
  - Installing cakephp/cakephp (3.5.0): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.5.0): Downloading (100%)         
  - Installing symfony/yaml (v3.3.6): Downloading (100%)         
  - Installing symfony/debug (v3.3.6): Downloading (100%)         
  - Installing symfony/console (v3.3.6): Downloading (100%)         
  - Installing symfony/filesystem (v3.3.6): Downloading (100%)         
  - Installing symfony/config (v3.3.6): Downloading (100%)         
  - Installing robmorgan/phinx (v0.8.1): Downloading (100%)         
  - Installing cakephp/migrations (1.7.1): Downloading (100%)         
  - Installing m1/env (2.1.0): Downloading (100%)         
  - Installing josegonzalez/dotenv (2.1.0): 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.1.0): Downloading (100%)         
  - Installing symfony/var-dumper (v3.3.6): Downloading (100%)         
  - Installing psy/psysh (v0.8.11): Downloading (100%)         
  - Installing jdorn/sql-formatter (v1.2.17): Downloading (100%)         
  - Installing symfony/process (v3.3.6): Downloading (100%)         
  - Installing symfony/finder (v3.3.6): Downloading (100%)         
  - Installing seld/phar-utils (1.0.1): Downloading (100%)         
  - Installing seld/jsonlint (1.6.1): Downloading (100%)         
  - Installing seld/cli-prompt (1.0.3): Downloading (100%)         
  - Installing justinrainbow/json-schema (5.2.1): Downloading (100%)         
  - Installing composer/spdx-licenses (1.1.6): Downloading (100%)         
  - Installing composer/semver (1.4.2): Downloading (100%)         
  - Installing composer/ca-bundle (1.0.7): Downloading (100%)         
  - Installing composer/composer (1.5.1): Downloading (100%)         
  - Installing cakephp/debug_kit (3.11.0): Downloading (100%)         
  - Installing cakephp/bake (1.4.1): Downloading (100%)         
  - Installing squizlabs/php_codesniffer (3.0.2): Downloading (100%)         
  - Installing cakephp/cakephp-codesniffer (3.0.1): 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 symfony/event-dispatcher ()
m1/env suggests installing m1/vars (For loading of configs)
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 /var/www/html/tmp/cache
Permissions set on /var/www/html/tmp/cache/models
Permissions set on /var/www/html/tmp/cache/persistent
Permissions set on /var/www/html/tmp/cache/views
Permissions set on /var/www/html/tmp/sessions
Permissions set on /var/www/html/tmp/tests
Permissions set on /var/www/html/tmp
Permissions set on /var/www/html/logs
Updated Security.salt value in config/app.php
```
完了です。

ServerNameで指定したUrlをブラウザーで読んでます。
今回は３．５なので、

下記のようになっていれば成功です。

![スクリーンショット 2017-08-27 22.15.58.png](https://qiita-image-store.s3.amazonaws.com/0/31394/0470bb15-d589-6a67-6241-afb93907b089.png)