LoginSignup
8
8

More than 5 years have passed since last update.

CakePHP 2.x系初期設定手順メモ

Last updated at Posted at 2015-04-17
  • DocumentRoot の下に cakephp というフォルダ名で設置したところからスタートです
  • Ubuntu 14.04, Apache2, MySQL の構成です
  • 作業メモなので必要最低限の事しか書いてません

ミドルウェア導入

$ sudo apt-get install apache2 libapache2-mod-php5 mysql-server php5-mysql

Apache設定変更

AllowOverride を None から All に変更

/etc/apache2/apache2.conf
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

mod_rewriteを有効

sudo a2enmod rewrite
sudo service apache2 restart

CakePHPの設定

  • 以下cakephp/app/の中の想定

権限変更

$ chmod -R 777 tmp

Config/core.phpの Security.salt 及びSecurity.cipherSeed の値を変更

  • a とか zとか足すだけでOK
Config/core.php
/**
 * A random string used in security hashing methods.
 */
    Configure::write('Security.salt', 'zDYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');

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

DBとユーザ作成

mysql> CREATE DATABASE cake CHARACTER SET utf8;
mysql> GRANT ALL ON *.* to hoge@localhost identified by 'piyo'; FLUSH PRIVILEGES;

DB設定

$ ./app/Console/cake bake


Welcome to CakePHP v2.X.X Console
---------------------------------------------------------------
App : app
Path: /vagrant/cakephp/app/
---------------------------------------------------------------
Your database configuration was not found. Take a moment to create one.
---------------------------------------------------------------
Database Configuration:
---------------------------------------------------------------
Name:  (設定上の名前。デフォルトでOK)
[default] > 
Datasource: (Mysql/Postgres/Sqlite/Sqlserver) (Mysqlでやります)
[Mysql] > 
Persistent Connection? (y/n) (コネクション永続化。パフォーマンスが良くなるのでy)
[n] > y
Database Host:  (ホスト)
[localhost] > 
Port?  (デフォルト3306ならnのまま)
[n] > 
User:  (MySQL上のアクセスユーザ名)
[root] > hoge
Password:  (パスワード)
> piyo
Database Name:  (DB名)
[cake] > 
Table Prefix?  (テーブルの接頭辞。無ければn)
[n] > 
Table encoding?  (エンコーディング設定。とりまn)
[n] > 

---------------------------------------------------------------
The following database configuration will be created:
---------------------------------------------------------------
Name:         default
Datasource:   Mysql
Persistent:   true
Host:         localhost
User:         hoge
Pass:         ***********
Database:     cake
---------------------------------------------------------------
Look okay? (y/n) (上記で良いかどうか)
[y] > 
Do you wish to add another database configuration?  (別のDB設定をするか)
[n] > 

Composer導入

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

DebugKitインストール

composer.jsonの作成

composer.json
{
  "require": {
    "cakephp/debug_kit": "2.2.*"
  }
}

composer実行

composer install

bootstrap.phpに以下の行を追加

Config/bootstrap.php
CakePlugin::load('DebugKit');
  • 実際使う場合AppController.phpに以下のフィールド追加
Controller/AppController.php
class AppController extends Controller {
    public $components = array('DebugKit.Toolbar');
}

以上、http://localhost/cakephp にアクセスし、メッセージがオールグリーンなのを確認して終了。
お疲れさまでした。

8
8
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
8
8