# Site Factory

> For the complete documentation index, see [llms.txt](https://doc.ibexa.co/en/5.0/llms.txt).

Site Factory allows creating multiple sites (SiteAccesses) from the back office.

Editions: Experience

Site Factory is a site management interface, integrated with the back office. It enables you to configure new sites without editing [YAML-based SiteAccess configuration](https://doc.ibexa.co/en/5.0/multisite/multisite_configuration/index.md).

> **Note: Note**
>
> A SiteAccess that you define for a site by following the [configuration](https://doc.ibexa.co/en/5.0/multisite/multisite_configuration/index.md) is always treated with higher priority than a SiteAccess created by using the Site Factory. For example, if you define a French site within a YAML file, and then create a site that uses the `fr` path in Site Factory, matchers ignore the second site.

Site Factory is disabled by default after installation.

If you plan to use Site Factory, you need to enable and configure it. To enable or disable Site Factory, follow:

- [Enable Site Factory section](#enable-site-factory)
- [Disable Site Factory section](#disable-site-factory)

## Enable Site Factory

To enable Site Factory, set the `ibexa_site_factory.enabled` [configuration key](https://doc.ibexa.co/en/5.0/administration/configuration/configuration/#configuration-files) to `true`.

### Configure designs

Next, configure Site Factory by adding empty SiteAccess groups. At least one empty group is required. The number of empty SiteAccess groups must be equal to the number of templates that you want to have when you create the new site.

In this example, you add two SiteAccess groups (`example_site_factory_group_1` and `example_site_factory_group_2`) that correspond to the two templates (`site1` and `site2`) that you add in the next step.

Add the groups under the `ibexa.siteaccess` [configuration key](https://doc.ibexa.co/en/5.0/administration/configuration/configuration/#configuration-files):

```yaml
ibexa:
    siteaccess:
        # ...
        groups:
            site_group: [import, site]
            storefront_group: [site]
            corporate_group: [corporate]
            example_site_factory_group_1: [ ]
            example_site_factory_group_2: [ ]

    system:
        example_site_factory_group_1:
        example_site_factory_group_2:
```

Uncomment the SiteAccess matcher (`Ibexa\SiteFactory\SiteAccessMatcher`):

```yaml
ibexa:
    siteaccess:
        match:
            '@Ibexa\SiteFactory\SiteAccessMatcher': ~
```

Next, add the [design engine](https://doc.ibexa.co/en/5.0/templating/design_engine/design_engine/index.md) configuration for new specific designs and their theme lists:

```yaml
ibexa_design_engine:
    design_list:
        example_1: [example_1_theme]
        example_2: [example_2_theme]
```

Finally, configure designs for empty SiteAccess groups:

```yaml
ibexa:
    system:
        example_site_factory_group_1:
            design: example_1
        example_site_factory_group_2:
            design: example_2
```

### Add site template configuration

Add thumbnails and names for your site templates:

```yaml
ibexa_site_factory:
    templates:
        site1:
            siteaccess_group: example_site_factory_group_1
            name: Example site 1
            thumbnail: /path/to/image/example-thumbnail_1.png
        site2:
            siteaccess_group: example_site_factory_group_2
            name: Example site 2
            thumbnail: /path/to/image/example-thumbnail_2.png
```

You can check the results of your work in the back office by going to **Site management** and selecting **Sites**.

There, you should be able to add a new site and choose a design for it.

### Define domains

To be able to see your site online, you need to define a domain for it.

> **Caution: Define domain for production environment**
>
> These steps are for `dev` environment only. If you want to define domains in production environment, you need to configure Apache or Nginx by yourself.

In the `.env` file change line 2 to: `COMPOSE_FILE=doc/docker/base-dev.yml:doc/docker/multihost.yml`

Take a look into the `doc/docker/multihost.yml` file. Here you can define domains. To add a new domain, add it in `command:` and under frontend and backend aliases as shown in the example below:

```yaml
services:
  web:
    command: /bin/bash -c "cd /var/www && cp -a doc/nginx/ibexa_params.d /etc/nginx && bin/vhost.sh --host-name=site.example.com --host-alias='admin.example.com test.example.com' --template-file=doc/nginx/vhost.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
    networks:
      frontend:
        aliases:
          - site.example.com
          - admin.example.com
          - test.example.com
      backend:
        aliases:
          - site.example.com
          - admin.example.com
          - test.example.com
```

Next, you must define the domains in `etc/hosts`:

`0.0.0.0 site.example.com admin.example.com test.example.com www.admin.example.com`

Then, run `docker-compose up`:

```bash
export COMPOSE_FILE="doc/docker/base-dev.yml:doc/docker/multihost.yml"
docker-compose up
```

Your sites should be now visible under:

- `http://site.example.com:8080/`
- `http://admin.example.com:8080/`
- `http://localhost:8080/`
- `http://test.example.com:8080/`

![Site Factory enabled](https://doc.ibexa.co/en/5.0/multisite/img/site_factory_site_list.png "Site Factory enabled")

### Define site directory

You can adjust the place where the directory of the new site is created (location with ID 2 by default). To do it, go to configuration files and under the `ibexa.system.<scope>.site_factory` [configuration key](https://doc.ibexa.co/en/5.0/administration/configuration/configuration/#configuration-files) add the following parameter:

```yaml
ibexa:
    system:
        default:
            site_factory:
                sites_location_id: 42
```

Now, all new directories are created under "Ibexa DXP".

### Provide access

The Site Factory is set up, now you can provide sufficient permissions to the users.

Set the below policies to allow users to:

- `site/view` - enter the Site Factory interface
- `site/create` - create sites
- `site/edit` - edit sites
- `site/change_status` - change status of the public accesses to `Live` or `Offline`
- `site/delete` - delete sites

For full documentation on how permissions work and how to set them up, see [the permissions section](https://doc.ibexa.co/en/5.0/permissions/permissions/index.md).

To learn how to use Site Factory, see [User Documentation](https://doc.ibexa.co/projects/userguide/en/5.0/website_organization/work_with_sites/).

## Disable Site Factory

Enabled Site Factory may cause following performance issues:

- [ConfigResolver](https://doc.ibexa.co/en/5.0/administration/configuration/dynamic_configuration/#configresolver) looks for SiteAccesses in the database
- Site Factory matchers are connected to the database in search for new SiteAccesses

You can disable Site Factory to boost ConfigResolver performance. Keep in mind that with disabled Site Factory you're unable to add new sites or use existing ones.

1. In `config/packages/ibexa_site_factory.yaml` change `enabled` to `false`.

2. In `config/packages/ibexa.yaml` comment the `ibexa.siteaccess.match: '@Ibexa\SiteFactory\SiteAccessMatcher': ~` if it's uncommented.

3. Remove separate connection to database in `config/packages/doctrine.yaml`.

```yaml
doctrine:
    dbal:
        connections:
            # ...
            # This connection is dedicated for SiteFactory to avoid known issues
            site_factory:
```

4. Remove separate cache pool in `config/packages/cache.yaml`.

```yaml
framework:
    cache:
        # ...
        pools:
            # This pool should be used only by SiteFactory bundle
            site_factory_pool:
```

The Site Factory should be disabled.
