[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Tutorials](../index.md) > [Deploying Nextcloud integrated with Object Storage](index.md) > Deploying Nextcloud on a VM from a Container Optimized Image

# Deploying Nextcloud on a Compute Cloud VM from a Container Optimized Image image, integrated with Yandex Object Storage

In this tutorial, you will deploy Nextcloud on a Compute Cloud [VM](../../concepts/vm.md) from a [Container Optimized Image](../../../cos/concepts/index.md) and connect an Object Storage [bucket](../../../storage/concepts/bucket.md) to it. To implement this solution, you will need a [domain name](https://en.wikipedia.org/wiki/Domain_name) for accessing resources in Nextcloud.

To deploy Nextcloud integrated with an Object Storage bucket on a VM from a Container Optimized Image image, do the following:

1. [Get your cloud ready](#before-you-begin).
1. [Create and set up a cloud network](#setup-network).
1. [Create a service account and static access key](#setup-sa).
1. [Create an Object Storage bucket](#create-bucket).
1. [Create a VM](#create-vm).
1. [Create an A resource record in your domain’s public DNS zone](#create-a-record).
1. [Configure Nextcloud on the VM](#setup-nextcloud).
1. [Test the solution](#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}

The cost of the proposed solution includes: 
* Fee for [disks](../../concepts/disk.md) and continuously running [VMs](../../concepts/vm.md) (see [Yandex Compute Cloud pricing](../../pricing.md)).
* Fee for using [public IP addresses](../../../vpc/concepts/address.md#public-addresses) (see [Yandex Virtual Private Cloud pricing](../../../vpc/pricing.md)).
* Fee for [data storage](../../../storage/concepts/bucket.md) in Object Storage and data [operations](../../../storage/operations/index.md) (see [Yandex Object Storage pricing](../../../storage/pricing.md)).
* If using Yandex Cloud DNS, fee for [DNS zones](../../../dns/concepts/dns-zone.md#public-zones) and public DNS queries (see [Cloud DNS pricing](../../../dns/pricing.md)).

## Set up a cloud network {#setup-network}

1. Create a [cloud network](../../../vpc/concepts/network.md#network) and [subnets](../../../vpc/concepts/network.md#subnet) for your new cloud infrastructure:
   
   {% list tabs group=instructions %}
   
   - Management console {#console}
   
     1. In the [management console](https://console.yandex.cloud), select the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) where you are going to create your infrastructure.
     1. Navigate to **Virtual Private Cloud**.
     1. In the top-right corner, click **Create network**.
     1. In the **Name** field, enter a name for the network: `nextcloud-network`.
     1. Make sure the **Create subnets** option is enabled and click **Create network**.
   
   {% endlist %}
1. Create a [security group](../../../vpc/concepts/security-groups.md) that allows the traffic required for your Nextcloud infrastructure:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
      1. Navigate to **Virtual Private Cloud**.
      1. In the left-hand panel, select ![shield](../../../_assets/console-icons/shield.svg) **Security groups**. 
      1. Click **Create security group**.
      1. In the **Name** field, enter `nextcloud-sg` for name.
      1. In the **Network** field, select `nextcloud-network` you created earlier.
      1. Under **Rules**, [create](../../../vpc/operations/security-group-add-rule.md) the following traffic management rules:

          | Traffic<br/>direction | Description | Port range | Protocol | Source /<br/>Destination name | CIDR blocks |
          | --- | --- | --- | --- | --- | --- |
          | Inbound | `http`           | `8080` | `TCP` | `CIDR` | `0.0.0.0/0` |
          | Inbound | `https`           | `443` | `TCP` | `CIDR` | `0.0.0.0/0` |
          | Inbound | `ssh`            | `22`   | `TCP`  | `CIDR` | `0.0.0.0/0` |
          | Egress | `any`           | `All` | `Any` | `CIDR` | `0.0.0.0/0` |
      1. Click **Create**.

    {% endlist %}

## Create a service account and static access key {#setup-sa}

To enable access from Nextcloud to the Object Storage bucket, create a [service account](../../../iam/concepts/users/service-accounts.md) and [static access key](../../../iam/concepts/authorization/access-key.md).

1. Create a service account:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
      1. Navigate to **Identity and Access Management**.
      1. Click **Create service account**.
      1. Enter a name for the service account: `nextcloud-sa`.
      1. Click ![plus](../../../_assets/console-icons/plus.svg) **Add role** and select [`editor`](../../../iam/roles-reference.md#editor).
      1. Click **Create**.

    {% endlist %}

1. Create a static access key:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
      1. Navigate to **Identity and Access Management**.
      1. In the left-hand panel, select ![FaceRobot](../../../_assets/console-icons/face-robot.svg) **Service accounts** and select the `nextcloud-sa` service account you created earlier.
      1. In the top panel, click ![plus](../../../_assets/console-icons/plus.svg) **Create new key** and select **Create static access key**.
      1. Click **Create**.
      1. Save the ID and the secret key.

          {% note alert %}

          After you close this dialog, the key value will no longer be available.

          {% endnote %}

    {% endlist %}

## Create an Object Storage bucket {#create-bucket}

Create the Object Storage bucket you will connect to Nextcloud:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Object Storage**.
  1. At the top right, click **Create bucket**.
  1. In the ** Name** field, enter a name for the bucket, e.g., `my-nextcloud-bucket`. The bucket name must be [unique](../../../storage/concepts/bucket.md#naming) within Yandex Object Storage.
  1. In the **Max size** field, specify the bucket size you need or enable **No limit**.
  1. Leave all the other parameters unchanged and click **Create bucket**.

{% endlist %}

## Create a VM {#create-vm}

Create the VM to deploy Nextcloud on:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/server.svg) **Virtual machines** and click **Create virtual machine**.
  1. Under **Boot disk image**, navigate to the **Container Solution** tab and click **Configure**. In the window that opens:

      1. Navigate to the **Docker Compose** tab and copy the `compose.yaml` [docker compose specification](https://github.com/nextcloud/all-in-one/blob/main/compose.yaml) from the official Nextcloud repository on GitHub into the field that opens.
      1. Click **Apply**.
  1. Under **Location**, select an [availability zone](../../../overview/concepts/geo-scope.md) for your VM.
  1. Under **Disks and file storages**, set a disk size of at least `40 GB`.
  1. Under **Computing resources**, select the `2 vCPU 4 GB RAM` configuration.

      This configuration will be enough to accommodate simultaneous operations by up to 10 users. If there are more active users, provide more available resources for the VM.
  1. Under **Network settings**:

      * In the **Subnet** field, select `nextcloud-network` and the subnet in your new VM's availability zone.
      * In the **Public IP address** field, leave the `Auto` value to assign the VM a random public IP address from the Yandex Cloud pool.
      * In the **Security groups** field, select `nextcloud-sg`.
  1. Under **Access**, select **SSH key** and specify the VM access credentials:

      * In the **Login** field, enter a username, e.g., `yc-user`. Do not use `root` or other reserved usernames. For operations requiring root privileges, use the `sudo` command.
      * In the **SSH key** field, select the SSH key saved in your [organization user](../../../organization/concepts/membership.md) profile.
        
        If there are no SSH keys in your profile or you want to add a new key:
        
        1. Click **Add key**.
        1. Enter a name for the SSH key.
        1. Select one of the following:
        
            * `Enter manually`: Paste the contents of the public SSH key. You need to [create](../../operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair on your own.
            * `Load from file`: Upload the public part of the SSH key. You need to create an SSH key pair on your own.
            * `Generate key`: Automatically create an SSH key pair.
            
              When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the `/home/<user_name>/.ssh` directory. In Windows, unpack the archive to the `C:\Users\<user_name>/.ssh` directory. You do not need additionally enter the public key in the management console.
        
        1. Click **Add**.
        
        The system will add the SSH key to your organization user profile. If the organization has [disabled](../../../organization/operations/os-login-access.md) the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.
  1. Under **General information**, specify the VM name: `nextcloud-vm`.
  1. Click **Create VM**.

{% endlist %}

{% note tip %}

To ensure that your new VM's [public IP address](../../../vpc/concepts/address.md#public-addresses) does not change in the future if the VM is stopped, [make that address static](../../../vpc/operations/set-static-ip.md).

{% endnote %}

## Create an A resource record in your domain’s public DNS zone {#create-a-record}

To complete this step, you will need a registered domain name, e.g., `example.com`.

To route your domain's incoming requests to the VM you created earlier, in your [public DNS zone](../../../dns/concepts/dns-zone.md#public-zones), create an [`A` resource record](../../../dns/concepts/resource-record.md#a) pointing to the VM's public IP address. Further steps to follow will depend on whether your domain is managed by [Yandex Cloud DNS](../../../dns/index.md) or a third-party DNS provider.

{% cut "**If your domain is managed by Yandex Cloud DNS**" %}
 
{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Cloud DNS**.
  1. Select the DNS zone you need, click **Create record**, and do the following in the window that opens:

      {% note info %}

      If you do not have a public DNS zone for the required domain name yet, [create](../../../dns/operations/zone-create-public.md) one.

      {% endnote %}

      1. In the **Name** field, select `Create subdomain` and enter `nextcloud` to create a subdomain, e.g., `nextcloud.example.com`, in your domain zone.
      1. In the **Type** field, select `A`.
      1. In the **Data** field, specify the VM's public IP address.

          You can look up the VM's public IP address in the [management console](https://console.yandex.cloud) by checking the **Network** section's **Public IPv4 address** field on the VM information page.
      1. Keep the other settings unchanged and click **Create**.

{% endlist %}

{% endcut %}

{% cut "**If your domain is managed by an external DNS provider**" %}

Add an A resource record with the following properties to your DNS provider or your own DNS server:

* Host: `nextcloud.<your_domain_name>.`
* Type: `A`
* Value: `<VM_IP_address>`

{% endcut %}

## Configure Nextcloud on a VM {#setup-nextcloud}

Follow this tutorial to perform the initial setup of your Nextcloud instance and integrate an Object Storage bucket into Nextcloud.

### Perform basic Nextcloud setup {#initialize}

Configure the Nextcloud solution on your new VM using the Nextcloud web interface:

1. In your browser, enter the subdomain you registered earlier with port `8080`, e.g., `https://nextcloud.example.com:8080`.

    You will see a warning about an insecure connection, as your Nextcloud instance does not have a configured [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) certificate yet. Proceed to the page despite the warning; Nextcloud will later automatically set up a certificate for your instance.
1. In the window that opens, copy the passphrase from the **Passphrase** field.

    {% note warning %}

    Displayed only once, this passphrase cannot be retrieved again. Without it, you will not be able to get the administrator password or complete your Nextcloud setup.

    {% endnote %}
1. Click **Open Nextcloud AIO login**.
1. In the **Nextcloud AIO Login** window, paste the passphrase you copied and click **Log in**.
1. In the **New AIO instance** section of the next window, enter the domain name used to access your Nextcloud instance (e.g., `nextcloud.example.com`) and click **Submit Domain**.
1. In the **Optional containers** section of the next window, disable `Nextcloud Talk` and click **Save changes**.

    For this tutorial, this module is optional. You can install it later via the Nextcloud admin interface if needed.
1. Click **Download and start containers**.

    The download and startup of the required containers may take several minutes. Wait for this process to complete.
1. Once all containers are running, the browser window will display the admin password for your Nextcloud instance in the **Initial Nextcloud password:** field. Save this password, then click **Open your Nextcloud**.
1. On the authentication screen, enter `admin` as the username and the password you got in the previous step, then click **Log in**.

### Set up integration with your Object Storage bucket {#integrate-bucket}

1. Open the application management menu. To do this, click the user icon in the top-right corner of the screen and select ![plus](../../../_assets/console-icons/plus.svg) **Apps** from the context menu.
1. In the window that opens, select ![person](../../../_assets/console-icons/person.svg) **Your apps** in the left-hand panel.
1. In the list that opens, find the `External storage support` application and click **Enable** in the row with it.

    If needed, enter your Nextcloud administrator password in the pop-up window to confirm the operation.
1. Open the main settings menu. To do this, click the user icon in the top-right corner of the screen and select ![admin-icon](../../../_assets/tutorials/integrate-nextcloud/admin-icon.svg) **Administration settings** from the context menu.
1. In the window that opens, select ![app-dark-icon](../../../_assets/tutorials/integrate-nextcloud/app-dark-icon.svg) **External storage** in the left-hand panel under **Administration** and specify the Object Storage integration settings under **External storage** in the window that opens:

    1. In the **External storage** section, select `Amazon S3`.
    1. In the **Authentication** section, select `Access key`.
    1. In the **Configuration** section:

        * In the **Bucket** field, enter the name of the bucket you created earlier, e.g., `my-nextcloud-bucket`.
        * In the **Hostname** field, specify `storage.yandexcloud.net`.
        * In the **Port** field, specify `443`.
        * In the **Access key** field, paste the ID of the static access key you created earlier.
        * In the **Secret key** field, paste the secret key of the static access key you created earlier.
    1. Under **Available for**, enable **All people**.
    1. On the right side of the section you are editing, click the ![check](../../../_assets/console-icons/check.svg) icon to save your changes.

        Enter your Nextcloud administrator password in the pop-up window to confirm the operation.

## Test the solution {#test}

To test Object Storage integration with Nextcloud, do the following:

1. On your local computer, open a browser and enter the domain name of your deployed Nextcloud instance in the address bar:

    ```text
    https://nextcloud.example.com
    ```
1. Log in to Nextcloud using the `admin` username and the saved administrator password.
1. In the left pane of the top menu, select ![folder-fill](../../../_assets/console-icons/folder-fill.svg) **Files**.
1. In the left-hand menu, select **External storage** and then **AmazonS3**.
1. Click ![plus](../../../_assets/console-icons/plus.svg) **New** and select ![arrow-shape-up-from-line](../../../_assets/console-icons/arrow-shape-up-from-line.svg) **Upload files** to upload a file from your local computer to the storage.
1. Select a file on your local computer and upload it to the storage.

    The uploaded file will now appear in the Nextcloud storage named `AmazonS3`.
1. In Yandex Object Storage, [make sure](../../../storage/operations/objects/list.md) the file was uploaded to the bucket.

This completes the deployment of the Nextcloud instance and its integration with Object Storage storage.

## How to delete the resources you created {#clear-out}

1. Delete the resource record in [Yandex Cloud DNS](../../../dns/operations/resource-record-delete.md) or in your domain registrar's account.
1. If you created a public DNS zone, delete it in [Yandex Cloud DNS](../../../dns/operations/zone-delete.md) or in your domain registrar's account.
1. [Delete](../../operations/vm-control/vm-delete.md) the VM.
1. [Delete](../../../storage/operations/objects/delete.md) the objects you created in the bucket, then [delete](../../../storage/operations/buckets/delete.md) the bucket itself.
1. [Delete](../../../iam/operations/sa/delete.md) the service account.
1. Delete the [subnets](../../../vpc/operations/subnet-delete.md), [security group](../../../vpc/operations/security-group-delete.md), and [cloud network](../../../vpc/operations/network-delete.md) one by one.

#### See also {#see-also}

* [Manually deploying Nextcloud on a Compute Cloud VM or in a VM group, integrated with Yandex Object Storage](fault-tolerant.md)
* [Deploying Nextcloud integrated with Yandex Object Storage on a Compute Cloud VM or VM group with the help of Terraform](terraform.md)