CakePHPを設置してみる

CentOSにPHPのとりあえずの開発環境を作成してみる
の続き。

CakePHPを設置してみる。

.htaccessの有効化

.htaccess」が有効になってない場合は、
サーバにログインして、httpd.confのAllowOverrideにAllを指定し、Apacheを再起動して、
.htaccess」を有効にしておく。

$ sudo vi /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
    AllowOverride All
$ sudo service httpd restart

CakePHPのダウンロード

http://cakephp.jp/
からCakePHPの最新(現時点では2.4.4)をダウンロードする。

ダウンロードしたファイルを展開して、「cakephp」というディレクトリ名にして
ドキュメントルートに設置する。

core.phpの修正

cakephp/app/Config/core.phpを開き、Security.saltとSecurity.cipherSeedの所に
適当な値を指定する。

/**
 * A random string used in security hashing methods.
 */
	Configure::write('Security.salt', '(適当な文字列)');

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

database.phpの修正

cakephp/app/Config/database.php.defaultのファイル名をdatabase.phpに変更する。
loginとpasswordに「CentOSにMySQLとMemcacheのインストールしてみる
」で作成したユーザー名とパスワードを指定する。
databaseにはとりあえずtestを指定しておく。

public $default = array(
	'datasource' => 'Database/Mysql',
	'persistent' => false,
	'host' => 'localhost',
	'login' => '(MySQLのユーザー名)',
	'password' => '(MySQLのパスワード)',
	'database' => 'test',
	'prefix' => '',
	//'encoding' => 'utf8',
);

以上で、
http://サーバーのアドレス/cakephp/
にアクセスすると、CakePHPのトップページが表示される。

このままでも動作するが、「DebugKitが無い」と警告が出ているので下記の手順で入れる。

DebugKit

下記のページからDebugKitをダウンロードする。

cakephp/debug_kit · GitHub
https://github.com/cakephp/debug_kit

解凍して、「DebugKit」というフォルダ名にして、app/Pluginに設置する。

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::load('DebugKit');	←追加

app/Controller/AppController.phpを開いて、下記を追加する。

class AppController extends Controller {
	public $components = array('DebugKit.Toolbar');	←追加
}

以上で、
http://サーバーのアドレス/cakephp/
にアクセスすると、下記のCakePHPのトップページが表示され、DebugKitの警告も無くなる。

右上のアイコンをクリックすると、DebugKitのメニューが出る。