[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > Building a data platform > Using a Yandex Managed Service for Valkey™ cluster as a cache storage for 1C-Bitrix: Site Management

# Using a Yandex Managed Service for Valkey™ cluster as a cache storage for 1C-Bitrix: Site Management


# Using a Yandex Managed Service for Valkey™ cluster as a cache storage for 1C-Bitrix: Site Management

You can use a Yandex Managed Service for Valkey™ cluster as an external cache storage for a website on 1C-Bitrix: Site Management.

To set up caching:

1. [Set up your infrastructure](#deploy-infrastructure).
1. [Configure 1C-Bitrix: Website Management](#configure-bitrix).
1. [Check the result](#test).

If you no longer need the resources you created, [delete them](#clear-out).

## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).


### Required paid resources {#paid-resources}

* VM instance: use of computing resources, storage, public IP address, and OS (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).
* Yandex Managed Service for Valkey™ cluster: computing resources allocated to hosts, storage and backup size (see [Yandex Managed Service for Valkey™ pricing](../../managed-valkey/pricing.md)).

This tutorial uses the trial version of 1C-Bitrix with a 30-day trial period. You can check the cost of the product software versions on the [1C-Bitrix](https://www.1c-bitrix.ru) official website.


## Set up your infrastructure {#deploy-infrastructure}

{% list tabs group="instructions" %}

- Manually {#manual}

    1. [Create a network](../../vpc/operations/network-create.md) named `network-1c` with the **Create subnets** option disabled.
    1. In `network-1c`, [create a subnet](../../vpc/operations/subnet-create.md) with the following settings:

        * **Name**: `subnet-a`.
        * **Availability zone**: `ru-central1-a`.
        * **CIDR**: `192.168.0.0/24`.

    1. In `network-1c`, [create security groups](../../vpc/operations/security-group-create.md):

        1. Named `bitrix-sg`, for the VM in the cloud. [Set the following rules](../../vpc/operations/security-group-add-rule.md) for this security group:

            | Traffic<br>direction | Description | Port range | Protocol | Source /<br>Destination name | IPv4 CIDR |
            |------------------------|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
            | Outbound              | `ANY`                                                                            | `All`                                                                          | `Any`            | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |
            | Inbound               | `HTTP`                                                                           | `80`                                                                            | `TCP`                                       | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |
            | Inbound               | `EXT-HTTPS`                                                                      | `443`                                                                           | `TCP`                                       | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |
            | Inbound               | `SSH`                                                                            | `22`                                                                            | `TCP`                                       | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |

        1. Named `valkey-sg`, for the Yandex Managed Service for Valkey™ cluster. [Set the following rules](../../vpc/operations/security-group-add-rule.md) for this security group:

            | Traffic<br>direction | Description | Port range | Protocol | Source /<br>Destination name | IPv4 CIDR |
            |------------------------|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
            | Outbound              | `ANY`                                                                            | `All`                                                                          | `Any`            | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |
            | Inbound               | `EXT-HTTPS`                                                                      | `6379`                                                                          | `TCP`                                       | `Prefix`                                                                                    | `0.0.0.0/0`                                                                      |

    1. [Create a virtual machine](../../compute/operations/images-with-pre-installed-software/create.md) with the following configuration in Compute Cloud:

        * Under **Boot disk image**, select a [1C-Bitrix](https://yandex.cloud/en/marketplace/products/yc/bitrix-1c-centos-7) image.
        * Under **Network settings**, set the following settings:

            * **Subnet**: `network-1c` and `subnet-a`.
            * **Public IP address**: `Auto`.
            * **Security groups**: `bitrix-sg`.
            * **Internal IPv4 address**: `Auto`.

    1. [Connect to the VM](../../compute/operations/images-with-pre-installed-software/operate.md#vm-connect) over SSH and install the dependencies:

        ```bash
        sudo yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo && \
        sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
        sudo yum install yum-utils && \
        sudo yum-config-manager --enable remi-php74 && \
        sudo yum update && \
        php -v
        ```

        The last command will show the PHP version installed on the VM. For 1C-Bitrix to run correctly, update the PHP version to 7.4 or higher.

    1. Install 1C-Bitrix: Site Management on the VM. Do it by going to `http://<VM_public_IP_address>/` in your browser and following the installer instructions.

    1. Create a test website on 1C-Bitrix.

    1. [Create](../../managed-valkey/operations/cluster-create.md) a Yandex Managed Service for Valkey™ cluster with the following configuration:

        * **Valkey version**: `9.1`.
        * **Persistence**: `On replicas`.
        * **Network settings**: `network-1c` as the network and `valkey-sg` as the security group.
        * **DBMS settings**:
            * **Password**: `default`.
            * **Configure** → **Maxmemory policy**: `ALLKEYS LRU`. This setting will allow Valkey™ to delete the oldest keys when running out of memory.
        * **Access from WebSQL**: Enabled.


- Terraform {#tf}

  1. If you do not have Terraform yet, [install it](terraform-quickstart.md#install-terraform).
  1. [Get the authentication credentials](terraform-quickstart.md#get-credentials). You can add them to environment variables or specify them later in the provider configuration file.
  1. [Configure and initialize a provider](terraform-quickstart.md#configure-provider). Instead of manually creating the provider configuration file, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).
  1. Place the configuration file in a separate working directory and [specify the parameter values](terraform-quickstart.md#configure-provider). If you have not added the authentication credentials to environment variables, specify them in the configuration file.
  1. Download the [yc-valkey-as-1c-cache-storage.tf](https://github.com/yandex-cloud-examples/yc-valkey-1c-locks/blob/main/yc-valkey-as-1c-cache-storage.tf) configuration file to the same working directory.

      This file describes:

      * Network.
      * Subnets.
      * Security groups.
      * Yandex Managed Service for Valkey™ cluster.
      * Virtual machine with public internet access and preinstalled 1C-Bitrix: Site Management.
      * Settings for 1C-Bitrix: Site Management.

          {% note info %}

          Specific 1C-Bitrix settings may vary depending on your custom implementation. You can find cache configuration examples in the [product documentation](https://dev.1c-bitrix.ru/).

          {% endnote %}

  1. In `yc-valkey-as-1c-cache-storage.tf`, specify the value for the `valkey_password` variable, i.e., the Yandex Managed Service for Valkey™ cluster user password.

  1. Validate your Terraform configuration using this command:

      ```bash
      terraform validate
      ```
      Terraform will display any configuration errors detected in your files.

  1. Create the required infrastructure:

      1. Run this command to view the intended changes:
      
         ```bash
         terraform plan
         ```
      
         If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
      
      1. If everything looks correct, apply the changes:
      
         1. Run this command:
      
            ```bash
            terraform apply
            ```
      
         1. Confirm updating the resources.
         1. Wait for the operation to complete.

      All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

  After you create the resources, the terminal will display the following connection settings:

  * `valkey_endpoint`: Endpoint for connection to the Yandex Managed Service for Valkey™ cluster.
  * `bitrix_vm_public_ip`: Public IP address of the VM running 1C-Bitrix: Site Management.


{% endlist %}

## Configure 1C-Bitrix {#configure-bitrix}

{% list tabs group="instructions" %}

- Manually {#manual}

  1. [Connect to the VM](../../compute/operations/images-with-pre-installed-software/operate.md#vm-connect) running 1C-Bitrix over SSH.

  1. Navigate to the website folder and open the additional settings file named `bitrix/.settings_extra.php`.

  1. Specify Valkey™ as the caching option and the Yandex Managed Service for Valkey™ cluster address:

      ```php
      <?php
      return [
          'cache' => [
              'value' => [
                  'type' => [
                      'class_name' => '\Bitrix\Main\Data\CacheEngineRedis',
                  ],
                  'redis' => [
                      'servers' => [
                          [
                              'host' => 'c-<cluster_ID>.rw.mdb.yandexcloud.net',
                              'port' => 6379,
                          ],
                      ],
                      'serializer' => \Redis::SERIALIZER_IGATBINARY ?? null,
                  ],
              ],
              'readonly' => true,
          ],
      ];
      ```

      You can get the cluster ID with the [list of clusters](../../managed-valkey/operations/cluster-list.md#list-clusters) in the folder.

      {% note info %}

      Specific 1C-Bitrix settings may vary depending on your custom implementation. You can find cache configuration examples in the [product documentation](https://dev.1c-bitrix.ru/).

      {% endnote %}


- Terraform {#tf}

  1C-Bitrix: Site Management is configured when you create the VM. No additional setup is required.


{% endlist %}


## Check the result {#test}

1. Authenticate to your website and navigate to the control panel.
1. Open **Settings** → **Productivity settings** → **Productivity panel**.
1. On the **Bitrix** tab, make sure that caching is enabled with Valkey™ as storage.
1. Make sure data actually ends up in the cluster:

    1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
    1. [Navigate](https://console.yandex.cloud/link/managed-valkey) to **Yandex Managed Service for&nbsp;Valkey™**.
    1. Click the name of your cluster and select the **Monitoring** tab. The page that opens will display performance charts for the cluster.
    1. Make sure that clients have appeared, stored data and traffic are growing, and there is disk write activity on replicas due to enabled persistence.

## Delete the resources you created {#clear-out}

Delete the resources you no longer need to avoid paying for them:

{% list tabs group=instructions %}

- Manually {#manual}

    1. [Delete the Yandex Managed Service for Valkey™ cluster](../../managed-valkey/operations/cluster-delete.md).
    1. [Delete the VM](../../compute/operations/vm-control/vm-delete.md).
    1. If you reserved public static IP addresses, release and [delete them](../../vpc/operations/address-delete.md).


- Terraform {#tf}

    1. In the terminal window, go to the directory containing the infrastructure plan.
    
        {% note warning %}
    
        Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
    
        {% endnote %}
    
    1. Delete resources:
    
        1. Run this command:
    
            ```bash
            terraform destroy
            ```
    
        1. Confirm deleting the resources and wait for the operation to complete.
    
        All the resources described in the Terraform manifests will be deleted.


{% endlist %}