Skip to content

Instantly share code, notes, and snippets.

@arfaram
Last active February 19, 2018 13:47
Show Gist options
  • Save arfaram/b9ffc12d9df008bdd54e0acb6e53c59b to your computer and use it in GitHub Desktop.
Save arfaram/b9ffc12d9df008bdd54e0acb6e53c59b to your computer and use it in GitHub Desktop.
Multisiteaccess settings for ezplatform V2 (with symfony3.4) using individuall repository, (sub)domains, storage and cache pool filesystem (not recommended adapter) or redis example

ezplatform.yml

ezpublish:
    repositories:
        default:
            storage: ~
            search:
                engine: '%search_engine%'
                connection: default
        site1_repo:
            storage:
                engine: '%search_engine%'
                connection: site1_conn
            search:
                engine: '%search_engine%'
                connection: site1_conn
    siteaccess:
        list: [site, admin, site1, admin_site1]
        groups:
            site_group: [site]
            site1_group: [site1, admin_site1]
            admin_group: [admin, admin_site1]
        default_siteaccess: site
        match:
            URIElement: 1
            Map\Host:
                site1.ezplatform.dev: site1
                admin_site1.ezplatform.dev: admin_site1
    system:
          #...
          site1_group:
            cache_service_name: '%cache_pool_site1%'
            var_dir: var/site1
            repository: site1_repo
            content:
                default_ttl: '%httpcache_default_ttl%'
            languages:
                - ger-DE
                - eng-GB

config.yml

doctrine:
    dbal:
        connections:
            default:
                driver: '%database_driver%'
                host: '%database_host%'
                port: '%database_port%'
                dbname: '%database_name%'
                user: '%database_user%'
                password: '%database_password%'
                charset: UTF8
            site1_conn:
                driver: '%database_driver%'
                host: '%database_host%'
                port: '%database_port%'
                dbname: '%database_name_site1%'
                user: '%database_user%'
                password: '%database_password%'
                charset: UTF8
#...
#below adapter is generally the slowest due to the overhead of file IO. If throughput is paramount, the in-memory adapters (such as APCu, Memcached, and Redis) or the database adapters (such as Doctrine and PDO & Doctrine) are recommended.
framework:
    #...
    cache:
        pools:
            cache.site1:
                adapter: cache.adapter.filesystem
                public: true

default_parameters.yml

parameters:
    #...
    database_name_site1: '%env(DATABASE_NAME_SITE1)%'
    cache_pool_site1: '%env(CACHE_POOL_SITE1)%'
    #Next cache pool should be added as a service
    env(CACHE_POOL_SITE1): "cache.site1"
    site1_defaultLifetime: ~

parameters.yml

parameters:
    env(DATABASE_NAME_SITE1): ezplatform-ee-site1

services.yml

services:
    cache.app.site1:
        class: AppBundle\Cache\Site1CachePool
        arguments:
            - '%cache_pool_site1%'
            - '%site1_defaultLifetime%'
            - '%kernel.cache_dir%/site1'

Site1CachePool.php

<?php

namespace AppBundle\Cache;

use Symfony\Component\Cache\Adapter\FilesystemAdapter;

use Symfony\Component\Cache\Traits\FilesystemTrait;

class Site1CachePool extends FilesystemAdapter
{
    use FilesystemTrait;

    public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
    {
        parent::__construct('', $defaultLifetime);
        $this->init($namespace, $directory);

    }

}

ezplatform.yml

Note: See example siteaccess setting example at the end of this file

ezpublish:
    system:
        site1_group:
            cache_service_name: '%cache_pool%'

config.yml

imports:
    #...
    - { resource: 'cache_pool/cache.redis.yml' }

default_parameters.yml

    cache_pool: '%env(CACHE_POOL)%'
    env(CACHE_POOL): 'cache.redis'
    cache_dsn: '%env(CACHE_DSN)%'
    env(CACHE_DSN): 172.19.0.21:6379

did you need a Redis docker conatiner?

1. Pull images:
    docker pull rarfaoui/redis

2. Create new Docker private network:
    docker network create --subnet=172.19.0.0/16 dockernet1

3 Run the image
    docker run -ti -p 63791:6379 --net dockernet1 --ip 172.19.0.21 --name=redis rarfaoui/redis /bin/bash 

4 Run redis inside the container

  /etc/init.d/redis-server start
  
  Note: Now the container is created, later use this command to start redis-server automatically:
  docker start redis && docker exec -ti redis bash -c "/etc/init.d/redis-server start"

5.Test 
  $redis-cli
    set test "works"
    get test
    
6. be sure that php-redis extension is installed in your php server 

Extended ezplatform.yml settings

Note: The example below demonstrate multisite settings using 1 common DB, 1 storage, two languages and diffrent URLs and

ezpublish:
    # HttpCache settings, By default 'local' (Symfony HttpCache Proxy), by setting it to 'http' you can point it to Varnish
    # You may also set it to 'fastly' if you want to use the fastly CDN
    http_cache:
        purge_type: '%purge_type%'

    # Repositories configuration, setup default repository to support solr if enabled
    repositories:
        default:
            storage: ~
            search:
                engine: '%search_engine%'
                connection: default
    # Siteaccess configuration, with one siteaccess per default
    siteaccess:
        list:
            - site1
            - admin_site1
            - site2
            - admin_site2
        groups:
            # WARNING: Do not remove or rename this group.
            # It's used to distinguish common siteaccesses from admin ones.
            # In case of multisite with multiple admin panels, remember to add any additional admin siteaccess to this group.
            admin_group:
                - admin_site1
                - admin_site2

            frontend_group:
                - site1
                - site2

        default_siteaccess: site1
        match:
            URIElement: 1

            Map\Host:
                site1.ezplatform.localhost: site1
                site2.ezplatform.localhost: site2

    # System settings, grouped by siteaccess and/or siteaccess group
    system:

        # WARNING: Do not remove or rename this group.
        admin_group:
            cache_service_name: '%cache_pool%'
            var_dir: var/site
            languages: [ger-DE, eng-GB]
            content:
                default_ttl: '%httpcache_default_ttl%'
            http_cache:
                purge_servers: ['%purge_server%']
                fastly:
                    service_id: '%fastly_service_id%'
                    key: '%fastly_key%'

        #custom siteacesses
        frontend_group:
            cache_service_name: '%cache_pool%'
            var_dir: var/site
            languages: [ger-DE, eng-GB]
            content:
                default_ttl: '%httpcache_default_ttl%'
            http_cache:
                purge_servers: ['%purge_server%']
                fastly:
                    service_id: '%fastly_service_id%'
                    key: '%fastly_key%'
        site1:
            cache_service_name: '%cache_pool%'  ## bug: should be available from frontend_group
            content:
                tree_root:
                    location_id: 55

        site2:
            cache_service_name: '%cache_pool%'  ## bug: should be available from frontend_group
            content:
                tree_root:
                    location_id: 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment