m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

cakephp3.0(dev)をセットアップする

cakephpの3.xのプレビュー版が出ているのを知った。

使いやすくなっているか気になったのでちょっと調査

環境

OS

CentOS 64bit

PHP

5.5.5

webサーバ

面倒なんで、phpのビルドインサーバを使用

セットアップ

ディレクトリを作成
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir dev.example.com
[root@localhost html]# cd dev.example.com/
[root@localhost html]#
composer
# composer
[root@localhost dev.example.com]# curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /var/www/html/dev.example.com/composer.phar
Use it: php composer.phar
[root@localhost dev.example.com]#
プロジェクトを作成
# プロジェクトを作成
[root@localhost dev.example.com]# php composer.phar create-project -s dev cakephp/app
Installing cakephp/app (dev-master 06393994781aedc794d811c957827ae3e0918d61)
  - Installing cakephp/app (dev-master master)
    Cloning master

Created project in /var/www/html/dev.example.com/app
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing cakephp/cakephp (3.0.x-dev f3ccd7f)
    Cloning f3ccd7fcc7546e4470d8abae17e8fa70de082bba

  - Installing d11wtq/boris (v1.0.8)
    Downloading: 100%

Writing lock file
Generating autoload files
Created `Config/app.php` file
Permissions set on /var/www/html/dev.example.com/app/tmp/cache
Permissions set on /var/www/html/dev.example.com/app/tmp/cache/models
Permissions set on /var/www/html/dev.example.com/app/tmp/cache/persistent
Permissions set on /var/www/html/dev.example.com/app/tmp/cache/views
Permissions set on /var/www/html/dev.example.com/app/tmp/logs
Permissions set on /var/www/html/dev.example.com/app/tmp/sessions
Permissions set on /var/www/html/dev.example.com/app/tmp/tests
Permissions set on /var/www/html/dev.example.com/app/tmp
Updated Security.salt value in App/Config/app.php
Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]?
[root@localhost dev.example.com]#
ディレクトリを確認
# ディレクトリを確認
[root@localhost dev.example.com]# ls -la
合計 996
drwxr-xr-x 3 root root    4096  3月  5 20:22 2014 .
drwxr-xr-x 8 root root    4096  3月  5 20:20 2014 ..
drwxr-xr-x 8 root root    4096  3月  5 20:24 2014 app
-rwxr-xr-x 1 root root 1004313  3月  5 20:21 2014 composer.phar
[root@localhost dev.example.com]#
app配下を確認
# app配下
[root@localhost dev.example.com]# cd app/
[root@localhost app]# ls -la
合計 60
drwxr-xr-x  8 root root 4096  3月  5 20:24 2014 .
drwxr-xr-x  3 root root 4096  3月  5 20:22 2014 ..
-rw-r--r--  1 root root   37  3月  5 20:22 2014 .gitignore
-rw-r--r--  1 root root  140  3月  5 20:22 2014 .htaccess
-rw-r--r--  1 root root  345  3月  5 20:22 2014 .travis.yml
drwxr-xr-x 10 root root 4096  3月  5 20:22 2014 App
drwxr-xr-x  2 root root 4096  3月  5 20:22 2014 Plugin
-rw-r--r--  1 root root 1176  3月  5 20:22 2014 README.md
drwxr-xr-x  4 root root 4096  3月  5 20:22 2014 Test
-rw-r--r--  1 root root  653  3月  5 20:22 2014 composer.json
-rw-r--r--  1 root root 3278  3月  5 20:23 2014 composer.lock
-rw-r--r--  1 root root  679  3月  5 20:22 2014 index.php
drwxr-xrwx  6 root root 4096  3月  5 20:22 2014 tmp
drwxr-xr-x  6 root root 4096  3月  5 20:23 2014 vendor
drwxr-xr-x  6 root root 4096  3月  5 20:22 2014 webroot
[root@localhost app]#
app/App配下
[root@localhost app]# ls -la App/
合計 40
drwxr-xr-x 10 root root 4096  3月  5 20:22 2014 .
drwxr-xr-x  8 root root 4096  3月  5 20:24 2014 ..
drwxr-xr-x  3 root root 4096  3月  5 20:23 2014 Config
drwxr-xr-x  4 root root 4096  3月  5 20:22 2014 Console
drwxr-xr-x  3 root root 4096  3月  5 20:22 2014 Controller
drwxr-xr-x  2 root root 4096  3月  5 20:22 2014 Lib
drwxr-xr-x  3 root root 4096  3月  5 20:22 2014 Locale
drwxr-xr-x  6 root root 4096  3月  5 20:22 2014 Model
drwxr-xr-x  8 root root 4096  3月  5 20:22 2014 Template
drwxr-xr-x  3 root root 4096  3月  5 20:22 2014 View
[root@localhost app]#
webroot
# ドキュメントroot
[root@localhost app]# ls -la webroot/
合計 40
drwxr-xr-x 6 root root 4096  3月  5 20:22 2014 .
drwxr-xr-x 8 root root 4096  3月  5 20:24 2014 ..
-rw-r--r-- 1 root root  170  3月  5 20:22 2014 .htaccess
drwxr-xr-x 2 root root 4096  3月  5 20:22 2014 css
-rw-r--r-- 1 root root  372  3月  5 20:22 2014 favicon.ico
drwxr-xr-x 2 root root 4096  3月  5 20:22 2014 files
drwxr-xr-x 2 root root 4096  3月  5 20:22 2014 img
-rw-r--r-- 1 root root 1245  3月  5 20:22 2014 index.php
drwxr-xr-x 2 root root 4096  3月  5 20:22 2014 js
-rw-r--r-- 1 root root  949  3月  5 20:22 2014 test.php
[root@localhost app]#

起動

ビルドインサーバでテスト起動
# ビルドインサーバ
[root@localhost app]# php -S 192.168.51.129:3000 -t webroot/
PHP 5.5.5 Development Server started at Wed Mar  5 20:36:21 2014
Listening on http://192.168.51.129:3000
Document root is /var/www/html/dev.example.com/app/webroot
Press Ctrl-C to quit.
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51592 [200]: /
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51593 [200]: /css/cake.generic.css
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51594 [200]: /img/cake.power.gif
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51595 [200]: /img/cake.icon.png
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51596 [200]: /favicon.ico
[Wed Mar  5 20:36:25 2014] 192.168.51.1:51597 [200]: /favicon.ico
[root@localhost app]#
画面

f:id:m_shige1979:20140305215448j:plain

データベースとDebugKitを追加

app配下へ移動
[root@localhost ~]# cd /var/www/html/dev.example.com/app/
[root@localhost app]# ls -la
合計 60
drwxr-xr-x  8 root root 4096  3月  5 20:24 2014 .
drwxr-xr-x  3 root root 4096  3月  5 20:22 2014 ..
-rw-r--r--  1 root root   37  3月  5 20:22 2014 .gitignore
-rw-r--r--  1 root root  140  3月  5 20:22 2014 .htaccess
-rw-r--r--  1 root root  345  3月  5 20:22 2014 .travis.yml
drwxr-xr-x 10 root root 4096  3月  5 20:22 2014 App
drwxr-xr-x  2 root root 4096  3月  5 20:22 2014 Plugin
-rw-r--r--  1 root root 1176  3月  5 20:22 2014 README.md
drwxr-xr-x  4 root root 4096  3月  5 20:22 2014 Test
-rw-r--r--  1 root root  653  3月  5 20:22 2014 composer.json
-rw-r--r--  1 root root 3278  3月  5 20:23 2014 composer.lock
-rw-r--r--  1 root root  679  3月  5 20:22 2014 index.php
drwxr-xrwx  6 root root 4096  3月  5 20:22 2014 tmp
drwxr-xr-x  6 root root 4096  3月  5 20:23 2014 vendor
drwxr-xr-x  6 root root 4096  3月  5 20:29 2014 webroot
[root@localhost app]#
app.phpを開いてデータベースの定義を編集
<?php
    ・
  ・
  ・
    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'root',
            'password' => 'password',
            'database' => 'cake_db01',
            'prefix' => false,
            'encoding' => 'utf8',
        ],

        /**
         * The test connection is used during the test suite.
         */
        'test' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'my_app',
            'password' => 'secret',
            'database' => 'test_myapp',
            'prefix' => false,
            'encoding' => 'utf8',
        ],
    ],
  ・
  ・
  ・
DebugKitをcloneで取得
[root@localhost app]# git clone https://github.com/cakephp/debug_kit.git Plugin/DebugKit
Cloning into 'Plugin/DebugKit'...
remote: Reusing existing pack: 5714, done.
remote: Counting objects: 47, done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 5761 (delta 13), reused 0 (delta 0)
Receiving objects: 100% (5761/5761), 1.40 MiB | 314.00 KiB/s, done.
Resolving deltas: 100% (2350/2350), done.
Checking connectivity... done.
[root@localhost app]#
App/Config/bootstrap.phpに追加
<?php
・
・
・
Plugin::load('DebugKit');
画面

f:id:m_shige1979:20140306000736j:plain

まとめ

バージョンが変わったのでディレクトリの構成がある程度変わったよう。
まだ、プレビュー版なのでなんとも言えない…
基本インストールはcomposerを使用したほうが楽な感じ、なんか色々設定が変わっているので必要な機能を試してみる。

templateにsmartyを使いたいけど、どうなるかな…