LoginSignup
6
7

More than 1 year has passed since last update.

EC-CUBE4 セッション情報の出力先をデータベースに変更

Last updated at Posted at 2018-12-07

"EC-CUBE 4.0 開発者向けドキュメントサイト" に記載されるようになりました。


まえおき

EC-CUBE4のセッション管理のデフォルトはファイル書き出しになっているので、Webサーバーの冗長化などを行ったときには各サーバーでセッション情報を管理してしまうと問題が発生するケースがあります。

そのため、セッション情報の書き出しを ファイル から データベース に変更します。

作業

1. PdoSessionHandler にデータベースの接続先を伝える

app/config/eccube/services.yaml
# ↓ここから
    Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
        arguments:
            - '%env(DATABASE_URL)%'
# ↑ここまでを追記

2. sessionPdoSessionHandler が使われるようにする

app/config/eccube/packages/framework.yaml
    session:
# ↓ここから
#        handler_id: session.handler.native_file
#        save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
# ↑ここまでをコメントアウト

# ↓ここから
        handler_id : Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
# ↑ここまでを追記

3. インストーラー実行時は、ファイルシステムが使われるようにする

app/config/eccube/packages/install/framework.yaml
framework:
  session:
    handler_id: session.handler.native_file
    save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'

4. マイグレーションファイル作成

php bin/console doctrine:migrations:generate
app/DoctrineMigrations/VersionYYYYMMDDHHMISS.php
    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE `sessions` (
    `sess_id` VARCHAR ( 128 ) NOT NULL PRIMARY KEY ,
    `sess_data` MEDIUMBLOB NOT NULL ,
    `sess_time` INTEGER UNSIGNED NOT NULL ,
    `sess_lifetime` MEDIUMINT NOT NULL
) COLLATE utf8_bin, ENGINE = InnoDB');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('drop table sessions');
    }

5. マイグレーション実行

php bin/console doctrine:migrations:migrate

以上です


参考:
https://symfony.com/doc/current/doctrine/pdo_session_storage.html

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