こんにちは。
忘れるよね。
只野です。
久々にCakePHPの開発環境を作ろうと既存のプロジェクトをGitリポジトリからCloneしたところ
動かん。
久々過ぎてCakePHPプロジェクトでまず何をすればよいのすっかり忘れた私である。私の記憶はところてん式なのだ。新しい記憶が増えると古い記憶はどんどん押し出されて消えていく。
なんやかんや解決したのだけれど、月日が立てばまた忘れるので自分の記憶を思い出させる意味を込めブログに残します。
CakePHPプロジェクトをGitCloneした時の流れ
composer update
CakePHPのルートディレクトリでcomposerの更新コマンドをターミナルで実行。これでCakePHPプロジェクトに必要なプラグインをインストールする。Windowsの場合は実行前にPHPパスを環境変数にしてする必要があったはず。
プロジェクトによるだろうけれどCakePHPのデフォルトプロジェクト状態だと、configフォルダの配下に「app_local.example.php」が存在しているはず。このファイル名を「app_local.php」に変更してDBの接続設定をする。これはローカル環境だけの設定ファイル。変更してもgit管理対象外にデフォルトではなっているのでgitコミットされることはない。
/*
* Connection information used by the ORM to connect
* to your application's datastores.
*
* See app.php for more configuration options.
*/
'Datasources' => [
'default' => [
'host' => 'localhost',
/*
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => 'dev_username',
'password' => 'dev_password',
'database' => 'dev_database',
/**
* If not using the default 'public' schema with the PostgreSQL driver
* set it here.
*/
//'schema' => 'myapp',
/**
* You can use a DSN string to set the entire configuration
*/
'url' => env('DATABASE_URL', null),
],
/*
* The test connection is used during the test suite.
*/
'test' => [
'host' => 'localhost',
//'port' => 'non_standard_port_number',
'username' => 'my_app',
'password' => 'secret',
'database' => 'test_myapp',
//'schema' => 'myapp',
'url' => env('DATABASE_TEST_URL', null),
],
],
「app_local.php」を開き「host」、「username」、「password」、「database」を自分の環境に合わせて書き直す。
bin/cake migrations migrate
CakePHPのプロジェクトルートフォルダで上記コマンドを実行する。そうするとちゃんとしたCakePHPプロジェクトであれば必要なDBテーブルを作成してくれる。独自でDBテーブルの管理をしているプロジェクトはしらん。あと「seed」と言われるDBの初期値を管理している情報もCakePHPプロジェクトだと存在する場合があるので、必要に応じて下記コマンドを実行する。
bin/cake migrations seed
おわり。



