CakePHP2.5.5を使ってみる。
以前、CakePHP1.3.6を一通りレビューした(こちらから一連のログがある)が、訳あってCakePHPをまた使ってみることになった。
以前のレビューに沿って、Cake2.5.5をMacOX+XAMPP+Eclipseでレビューする。
実行要件
Cake2.xの要件をCake book 2.xで見ると
- Apacheのmod_rewriteが使えること。
- PHP5.2.8以降であること。
- MySQLは4以降であること(その他、Postgre、SQLServer、SQLiteも使える)
と書いてある。
XAMPPは随分前にいれた1.7.3なので若干心配になってチェックをした。
まず、mod_rewriteは「アプリケーション」→「XAMPP」→「etc」のhttpd.confをみればよい。
Cakeは.htaccessを使うので、AloWOverrideのところも見ておく。httpd.confの主要なところは以下。
… LoadModule rewrite_module modules/mod_rewrite.so … <Directory /> Options FollowSymLinks AllowOverride All #XAMPP #Order deny,allow #Deny from all </Directory> …
自分のPCではEclipseのワークスペースにaliasを設定している。
Alias /workspace "/Users/tetsuya/Documents/workspace/" <Directory "/Users/tetsuya/Documents/workspace"> Allow from all </Directory>
次にPHPとMySQLのバージョンを確認しておく。XAMPP(のApacheとMySQL)を起動しておけば
http://localhost/phpmyadmin
でphpMyAdminを開くことができる。
.htaccessの編集
プロジェクト直下、app下、webroot下にある.htaccessのRewriteBaseを以下のように書き直す。
プロジェクト直下の.htaccess
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase /workspace/cake-2.5.5/ RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>
プロジェクト/app/.htaccess
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase /workspace/cake-2.5.5/app/ RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>
プロジェクト/app/webroot/.htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /workspace/cake-2.5.5/app/webroot/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
app/Config/core.phpのcypherを修正する。
/** * A random string used in security hashing methods. */ Configure::write('Security.salt', '[適当な30文字の文字列]'); /** * A random numeric string (digits only) used to encrypt/decrypt strings. */ Configure::write('Security.cipherSeed', '[適当な30文字の文字列]');
とりあえず、これで準備は完了。
app/Config/core.phpとbootstrap.phpにCacheエラーの対応をする。
CakePHP2からCacheのアクセス権でエラーが出るようになったので、iwakingさんのブログを参考にcore.phpとbootstrap.phpを修正する。
core.phpを修正する。
Cache::config('_cake_core_', array( 'engine' => $engine, 'prefix' => $prefix . 'cake_core_', 'path' => CACHE . 'persistent' . DS, 'serialize' => ($engine === 'File'), 'duration' => $duration, 'mask'=>0666 //ここ )); /** * Configure the cache for model and datasource caches. This cache configuration * is used to store schema descriptions, and table listings in connections. */ Cache::config('_cake_model_', array( 'engine' => $engine, 'prefix' => $prefix . 'cake_model_', 'path' => CACHE . 'models' . DS, 'serialize' => ($engine === 'File'), 'duration' => $duration, 'mask'=>0666 //ここ ));
bootstrap.phpに以下を追記する。
Cache::config('default', array(
'mask' => 0666,
));
app/tmpに書き込み権限をつける
/workspace/cake-2.5.5/appにcdして、
chmod -R 777 tmp
としてtmp配下に書き込み権限を付与する。