# 3. Deployment and Cloud Environments

### Prerequisites

* Your project already runs on **Preview**.
* You have permission to **purchase/provision** environments (billing).
* (Optional) You have access to **DNS** of the domain, if using a custom domain.

{% hint style="info" %}
**Dev** to test quickly. **Staging** to validate release. **Prod** for end users.
{% endhint %}

{% stepper %}
{% step %}

### Open Cloud Environments

* [ ] Go to **Project Settings → Cloud Environments**
  {% endstep %}

{% step %}

### Create the environment

* [ ] Click **Purchase Environment**
* [ ] Set the **name** of the environment (e.g.: `dev-myapp`, `staging-myapp`, `prod-myapp`)

{% hint style="info" %}
Choose a name that makes the environment type obvious. Prevents deploying to the wrong place.
{% endhint %}
{% endstep %}

{% step %}

### Configure domain and scaling

* [ ] (Optional) Configure a **domain** (if you want a custom URL)
* [ ] Configure the **scaling**

{% hint style="info" %}
Start smaller. Increase later if there is slowness, timeouts, or real load.
{% endhint %}
{% endstep %}

{% step %}

### Provision and wait until Ready

* [ ] Proceed with provisioning
* [ ] Wait for the status to become **Ready**

<details>

<summary>Expected time</summary>

Usually takes a few minutes. If it stays stuck for a long time, follow the "If it fails" section.

</details>
{% endstep %}

{% step %}

### Publish (deploy)

* [ ] Click **Publish** and deploy your project to this environment

{% hint style="info" %}
Avoid "deploy spam." If needed, wait a few minutes and try again.
{% endhint %}
{% endstep %}

{% step %}

### Validate the deploy

* [ ] Open the **URL** of the domain
* [ ] Confirm that the home page loads
* [ ] Log in and validate a critical flow (e.g.: create/edit a record)
  {% endstep %}
  {% endstepper %}

### If it fails

* **Deploy fails with error:** follow [Deployment issues](https://app.gitbook.com/s/XnYvLewhXbdSQIvAlbqN/solucao-de-problemas/problemas-de-deploy).
* **Environment “Ready”, but the URL doesn't open:** if using a custom domain, review DNS and wait for propagation.
* **Deploy completes, but the app doesn't start:** treat as a **runtime** and follow the diagnosis in the troubleshooting.
