Laravelインストール直後の初期設定
Laravelの初期設定は「app\config\app.php」と「app\config\database.php」を編集するだけだ。
タイムゾーンとロケールの設定
日本の場合は「timezone」を「Asia/Tokyo」にし、「locale」を「ja」にする。
/* |-------------------------------------------------------------------------- | Application Timezone |-------------------------------------------------------------------------- | | Here you may specify the default timezone for your application, which | will be used by the PHP date and date-time functions. We have gone | ahead and set this to a sensible default for you out of the box. | */ 'timezone' => 'Asia/Tokyo', /* |-------------------------------------------------------------------------- | Application Locale Configuration |-------------------------------------------------------------------------- | | The application locale determines the default locale that will be used | by the translation service provider. You are free to set this value | to any of the locales which will be supported by the application. | */ 'locale' => 'ja', /*
key文字列の設定
「key」には32文字のランダムな文字列を入れる。ただし「composer create-project」を使ったインストールでは自動的に挿入されているので不要である。
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => 'qvU0ZY5zXVOdVv1QGZ4MqWKL25jPdepT',
/*
文字列を作るのは面倒だけど、「laravel」のインストールフォルダにある「artisan」を使えば簡単だ。引数に「key:generate」を指定すれば文字列をapp.phpに勝手に反映してくれる。
C:\xampp\htdocs\laravel>php artisan key:generate Application key [qvU0ZY5zXVOdVv1QGZ4MqWKL25jPdepT] set successfully.
データベースの設定
もう一つ、データベースも設定するために、「app\config\database.php」を編集する。MySqlの場合、database.phpの中身でデフォルトから変更するのは
- database
- username
- password
の3項目のみになると思う。
phpMyAdminを使って「laravel」というDBを作ったので、以下のように「database」に「laravel」を指定する。
/* |-------------------------------------------------------------------------- | Default Database Connection Name |-------------------------------------------------------------------------- | | Here you may specify which of the database connections below you wish | to use as your default connection for all database work. Of course | you may use many connections at once using the Database library. | */ 'default' => 'mysql', /* |-------------------------------------------------------------------------- | Database Connections |-------------------------------------------------------------------------- | | Here are each of the database connections setup for your application. | Of course, examples of configuring each database platform that is | supported by Laravel is shown below to make development simple. | | | All database work in Laravel is done through the PHP PDO facilities | so make sure you have the driver for your particular database of | choice installed on your machine before you begin development. | */ 'connections' => array( 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'laravel', 'username' => 'username', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), ),