altere5's blog

I thought what I'd do was, I'd pretend I was one of those deaf-mutes. ( or shou'd i ? )

CakePHPの覚書

これはCakePHPをお勉強する上でのメモ書きです。

導入&設定関連

「Security.salt」が未設定

Notice (1024): Please change the value of 'Security.salt' in app/Config/core.php to a salt value specific to your application [CORE/Cake/Utility/Debugger.php, line 849]

これは「app/Config/core.php」内の197行目付近にある「Security.salt」の値を変更していない時に表示される警告。
ちなみに「Security.salt」とは暗号化処理を行う際に付与する文字列の事。対象の文字列が短い場合も、「salt」が一定の文字長を持つことでレインボーテーブルを用いた攻撃に対してある程度の効果を得ることが可能。

具体的には以下の部分。

/**
 * A random string used in security hashing methods.
 */
    Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');

 
解決策:例えば40文字以上のランダムな(又は推測されない)英数字を設定する事で警告は消える。

「Security.cipherSeed」が未設定

Notice (1024): Please change the value of 'Security.cipherSeed' in app/Config/core.php to a numeric (digits only) seed value specific to your application [CORE/Cake/Utility/Debugger.php, line 853]

これは「app/Config/core.php」内の202行目付近にある「Security.cipherSeed」の値を変更していない時に表示される警告。
ちなみに「Security.cipherSeed」とは暗号化又は複合化処理の際に利用される数字。

/**
 * A random numeric string (digits only) used to encrypt/decrypt strings.
 */
    Configure::write('Security.cipherSeed', '76859309657453542496749683645');

 
解決策:例えば28文字以上のランダムな(又は推測されない)数字を設定する事で警告は消える。

「timezone」が未設定

Warning: strtotime(): It is not safe to rely on the system's timezone settings.

これは「php.ini」でTimeZoneの設定が行われていない場合に表示される警告。

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Tokyo

解決策:適切なタイムゾーンを設定する事で警告は消える。

「database.php」が未作成

Warning (2): include_once(/usr/share/nginx/cakephp/app/Config/database.php) http://php.net/function.include-once: failed to open stream: No such file or directory [CORE/Cake/Model/ConnectionManager.php, line 69]

これは「database.php」が作成されていない場合に表示される警告。

cp app/Config/database.php.default app/Config/database.php

解決策:「database.php」を作成する事で警告は消える。

php-pdo」が未インストール

Error: Class 'PDO' not found

これは「PDO」の導入が行われていない場合に表示される警告。

yum install php-pdo

解決策:yumで「php-pdo」をインストールする事で警告は消える。

セッション管理用ディレクトリが未作成

Warning (2): session_start() http://php.net/function.session-start: open(/var/lib/php/session/sess_xxxxxxxxxxxxxxxxxxxxxxxxxx, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Model/Datasource/CakeSession.php, line 615]

これは「/var/lib/php/session」ディレクトリが作成されていない(且つ、作成できない)場合に表示される警告。

mkdir /var/lib/php/session
chown -R nginx /var/lib/php/session
chgrp -R nginx /var/lib/php/session

解決策:「/var/lib/php/session」ディレクトリを作成し書込み権限を与える事で警告は消える。

セッション管理にMemcachedを利用

「app/Config/core.php」で設定。

Configure::write('Session', array(
    'defaults' => 'cache',
    'handler' => array( 'config' => 'default' )
));

Cache::config('default', array(
    'engine' => 'Memcache', //[required]
    'duration' => 3600, //[optional]
    'probability' => 100, //[optional]
    'prefix' => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every cache file with this string
    'servers' => array(
        '127.0.0.1:11211' // localhost, default port 11211
    ), //[optional]
    'persistent' => true, // [optional] set this to false for non-persistent connections
    'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
));

190行目付近から始まるセッションの設定に設定を追加。 その後ろに必要な設定をさらに追加。
具体的な設定内容は284行目付近あたりの内容を参考に。

DebugKitが未導入

DebugKit is not installed. It will help you inspect and debug different aspects of your application.

これはDebugKitが未導入時に表示される警告。
導入は公式からダウンロードしたファイルを使って行う。
ファイルを展開し、「app/Plugin」配下にコピー。なお、この時ディレクトリ名は「DebugKit」に修正する。

次に「app/Config/bootstrap.php」を修正する。

/**
 * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
 * Uncomment one of the lines below, as you need. make sure you read the documentation on CakePlugin to use more
 * advanced ways of loading plugins
 *
 * CakePlugin::loadAll(); // Loads all plugins at once
 * CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
 *
 */
CakePlugin::loadAll();
CakePlugin::load('DebugKit');

65行目付近から記載されている導入手順に従って追記。
具体的には上記74及び75行目のように追記する。

CORESERVER関連

PHPのバージョンが「5.2.8」以下

Your version of PHP is too low. You need PHP 5.2.8 or higher to use CakePHP.

これはCORESERVERで利用可能なPHPのバージョンが5.2.8未満である為に表示される警告。CORESERVERではサーバ毎に導入されているPHPのバージョンが異なる事がある為注意が必要。
 
現状は明示的に利用するバージョンを指定する事で対応可能。 具体的には「.htaccess」に以下のように記述する。

AddHandler application/x-httpd-php53cgi.php

 
なお、この場合モジュール版ではなくCGI版として動作させる事になるので注意。

参考:http://www.coreserver.jp/help/index.php/phpcgi/