[CakePHP4].envを有効にする

LINEで送る
Pocket

  • config/bootstrap.php
if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
    $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
    $dotenv->parse()
        ->putenv()
        ->toEnv()
        ->toServer();
}
  • config/app_local.php

.gitignoreに入っているので削除すること

 'Security' => [
'salt' => env('SECURITY_SALT', 'SECURITY_SALT'),
],

'Datasources' => [
    'default' => [
        'host' => env('DB_HOST'),
        /*
         * 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' => env('DB_USER'),
        'password' => env('DB_PASSWORD'),

        'database' => env('DB_NAME'),

        /*
         * 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),
    ],
  • config/.env
export APP_NAME="hoge"
export DEBUG="true"
export APP_ENCODING="UTF-8"
export APP_DEFAULT_LOCALE="en_US"
export APP_DEFAULT_TIMEZONE="UTC"
export SECURITY_SALT="hogeeeeeeeeeeeeee"
export DB_HOST="hoge"
export DB_USER="hoge"
export DB_PASSWORD="hoge"
export DB_NAME="hoge"

 

Was this helpful?

0 / 0

コメントを残す 0

Your email address will not be published. Required fields are marked *