3月
29
WindowsServer×CakePHP3の初期設定
- POSTED BY 小谷松 丈樹 IN 調査
- No Comments
CakePHP初期設定
CakePHPのインストールまでは前回紹介したので、
その後のDB設定など必要な修正をご紹介。
主要技術・環境
- Windows Server 2012 R2
- PostgreSQL
作業
データベース接続設定
今回、DBにPostgreSQLを使用しているので、ドライバなど設定を書き換えます。
対象ファイルは
project/config/app.default.php です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', //'driver' => 'Cake\Database\Driver\Mysql', 'driver' => 'Cake\Database\Driver\Postgres', 'persistent' => false, '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', 'port' => '5432', 'username' => 'my_app', 'password' => 'secret', 'database' => 'my_app', 'encoding' => 'utf8', 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, 'log' => false, /** * Set identifier quoting to true if you are using reserved words or * special characters in your table or column names. Enabling this * setting will result in queries built using the Query Builder having * identifiers quoted when creating SQL. It should be noted that this * decreases performance because each query needs to be traversed and * manipulated before being executed. */ 'quoteIdentifiers' => false, /** * During development, if using MySQL < 5.6, uncommenting the * following line could boost the speed at which schema metadata is * fetched from the database. It can also be set directly with the * mysql configuration directive 'innodb_stats_on_metadata = 0' * which is the recommended value in production environments */ //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], //'init' => ["SET @@session.time_zone = 'Asia/Tokyo'","SET names utf8"], # PostgreSQLで使えない構文 'init' => ["SET TIME ZONE 'Asia/Tokyo'","SET NAMES 'UTF8'"], 'url' => env('DATABASE_URL', null), ], |
init に配列でクエリ指定すれば、DB接続時に自動的に流してくれます。
Amazon RDSはタイムゾーンの指定ができず、UTCになってしまうので、
タイムスタンプの値が9時間ずれて取得されるので、タイムゾーン設定のクエリを毎度接続時に流すようにします。
php.iniの下記のコメントアウトを外すのもお忘れなく。
1 2 |
;extension=php_pdo_pgsql.dll ;extension=php_pgsql.dll |
で、これでも動かない場合、こちらを参考に。
PHP本体フォルダ直下のlibpq.dllを、Wwindowsに認識させると動き出すと言うことである。
パスの通っているところにlibpq.dllを移動させて解決しました。Win鯖に塩。。
Security.salt
SALT の部分をランダムな値に書き換えます。
1 2 3 |
'Security' => [ 'salt' => env('SECURITY_SALT', '__SALT__'), ], |
結果
次回予告(予定)
CakePHP3のルーティングを学ぼう!