LoginSignup
11
10

More than 5 years have passed since last update.

CakePHP開発環境構築:XAMPP for Mac にComposerを利用して環境構築

Last updated at Posted at 2014-03-26

本当はVagrantで全部一発環境構築したけど、その下準備として。

CakePHP、Debugkit、PHPUnit、BoostCakeまで一気にインスト。

Composerは便利だな〜。

1.XAMPPインストール

(1)XAMPPをダウンロード

(2)XAMPPをインストール
(3)パスの確認
・php
cd /Applications/XAMPP/xamppfiles/bin/php
・htdocs
cd /Applications/XAMPP/xamppfiles/htdocs/
(4)XAMPPのPHPへパスを通す
export PATH=/Applications/XAMPP/bin:$PATH

2.ComposerでCakePHP・PHPUnitTest・debug_kit・boostcakeをインストール

(1)ルートディレクトリになるフォルダ作成
mkdir /Applications/xampp/xamppfiles/htdocs/example-app

#example-appは設定時に変更
(2)ディレクトリに移動してComposerをインストール
cd /Applications/xampp/xamppfiles/htdocs/example-app

#mac標準(SSLの認証回避が必要時) 
curl -sS -k https://getcomposer.org/installer | php


#example-appは設定時に変更
(3)ディレクトリ構成確認
Applications/xampp/xamppfiles/htdocs/example-app
                                        composer.phar

#example-appは設定時に変更
(4)composer.jsonに[cakephp]【phpunit_test】【debug_kit】【boost_cake】記載
vim composer.json
{
  "extra": {
    "installer-paths": {
      "app/Plugin/Migrations": ["cakedc/migrations"],
      "app/Plugin/Users": ["cakedc/users"],
      "app/Plugin/Search": ["cakedc/search"],
      "app/Plugin/Utils": ["cakedc/utils"],
      "app/Plugin/Datasources": ["cakephp/datasources"],
      "app/Plugin/DebugKit": ["cakephp/debug_kit"],
      "app/Plugin/BoostCake": ["slywalker/boost_cake"],
      "app/Plugin/aws-sdk-php": ["aws/aws-sdk-php"]
    }
  },
  "require" : {
    "php": ">=5.2",
    "ext-mcrypt": "*",
    "cakedc/migrations": "2.2.*",
    "cakedc/users": "2.0.*",
    "cakedc/search": "2.2.*",
    "cakedc/utils": "1.4.*",
    "cakephp/datasources": "2.3.x-dev",
    "cakephp/debug_kit": "2.2.*@dev",
    "cakephp/cakephp" : "2.4.*",
    "slywalker/boost_cake": "dev-master",
    "aws/aws-sdk-php": "2.*"
  },
  "require-dev": {
    "phpunit/phpunit": "3.7.*"
  }
}
(5)install実行
php composer.phar install
(6)updateが必要なとき
php composer.phar update

3.CakePHP bake実行

(1)bake 実行

アプリケーションを配置するappを作成

Vendor/bin/cake bake project --app app
(2)webroot/index.phpを相対パスに変更
vim ./webroot/index.php
define('CAKE_CORE_INCLUDE_PATH',ROOT . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP');
(3)webroot/test.phpを相対パスに変更
vim ./webroot/test.php
define('CAKE_CORE_INCLUDE_PATH',ROOT . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP');
(4)Shellの実行ファイルConsole/cake.phpのinclude_path
ini_set('include_path', $root . $ds . 'Vendor' . $ds . 'pear-pear.cakephp.org' . $ds . 'CakePHP' . PATH_SEPARATOR . ini_get('include_path'));
(5)Config/bootstrap.php修正

debugkit、boostcake Pluginを読み込む

// Pluginディレクトリ指定を相対パスで
App::build(array('Plugin' => array(ROOT . DS . 'Plugin' . DS)));

// composerのautoloadを読み込み
require ROOT . DS . 'Vendor' . DS . 'autoload.php';

// CakePHPのオートローダーをいったん削除し、composerより先に評価されるように先頭に追加する
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);
CakePlugin::loadAll();
(6) app/tmp のパーミッション変更
chmod -R 707 tmp
(7)example-app下に.htaccessを作成
vim .htaccess
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    app/webroot/    [L]
    RewriteRule    (.*) app/webroot/$1    [L]
</IfModule>

(8)/app/Controller/AppController.php 内で、debugkitコンポーネントの読込
vim app/Controller/AppController.php
 public $components = array('DebugKit.Toolbar'); // debugkit
(9)boostcake Helper設定
vim app/Controller/AppController.php
<?php
class AppController extends Controller {

    public $helpers = array(
        'Session',
        'Html' => array('className' => 'BoostCake.BoostCakeHtml'),
        'Form' => array('className' => 'BoostCake.BoostCakeForm'),
        'Paginator' => array('className' => '                                   BoostCake.BoostCakePaginator'),
    );

}
(10)boostcake AuthComponent設定
vim app/Controller/AppController.php
<?php
class AppController extends Controller {

    public $components = array(
        'Auth' => array(
            'flash' => array(
                'element' => 'alert',
                'key' => 'auth',
                'params' => array(
                    'plugin' => 'BoostCake',
                    'class' => 'alert-error'
                )
            )
        )
    );

}

[参考]

ComposerでCakePHPインストール

http://otukutun.hatenablog.com/entry/2013/12/03/153455
http://blog.yudsuzuk.com/composer-cakephp/
http://higan96.hatenablog.com/entry/2013/10/02/183809
http://bit.ly/1drgcV3

Boostcake

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10