# Production, staging and custom environments

URL: https://stack.logicaltech.it/docs/deploy/environments/

Create production, staging and custom environments in a LogiStack project, duplicate one into another, recolor them and set the default.

An environment is an isolated set of services, variables and domains inside a project. Services in one environment share a private network and can't reach services in another, so a staging app never talks to the production database by accident. Use environments to run the same project at different stages, such as **Production** and **Staging**, or to give a client their own copy.

## Environment kinds [#environment-kinds]

Every project starts with a **Production** environment. When you create another, you pick its **Kind**:

| Kind | Typical use |
|---|---|
| **Production** | What your users reach |
| **Staging** | A pre-release copy for testing |
| **Preview** | A short-lived copy for a pull request. LogiStack creates these itself; see [Preview environments](./preview-environments.mdx) |
| **Custom** | Anything else, like `demo` or `client-acme` |

The kind sets the default color of the environment's dot. It doesn't change how services run.

## Create an environment [#create-an-environment]

<Steps>
<Step>

### Open the project [#open-the-project]

Select **Projects** in the sidebar and open the project. The environment tabs sit above the services.

![The Storefront project page with its environment tabs and services](/screens/project.webp)

</Step>
<Step>

### Add the environment [#add-the-environment]

Select **New environment**. In the dialog, enter a **Name** such as `Staging` and pick the **Kind**. Select **Create environment**.

</Step>
<Step>

### Add services [#add-services]

The new environment is empty. Select **New service** to add services to it, or [duplicate an environment](#duplicate-an-environment) instead to start from a copy.

</Step>
</Steps>

## Change an environment [#change-an-environment]

Select the settings icon next to the environment tabs (labelled `<name> settings`) to open its menu:

- **Open by default**: the project opens on this environment.
- **Variables**: the variables every service in this environment inherits. See [Environment variables](./environment-variables.mdx#plain-variables).
- **Duplicate…**: start a new environment from this one. See below.
- **Export manifest**: download the environment as a YAML manifest.
- **Color**: pick one of six colors for the environment's dot, shown across the dashboard.

![The settings menu of the Production environment, with Open by default, Variables, Duplicate, Export manifest and the colors](/screens/environment-menu.webp)

## Duplicate an environment [#duplicate-an-environment]

Duplicating creates a new environment in the same project with the services, Git stacks, settings and config files of another, for example **Staging** from **Production**. You need permission to change the project.

| Copied | Not copied |
|---|---|
| Services, with their source, build, resources, health checks and config files | Domains: a hostname points at one environment |
| Stacks deployed from Git | Volume and database data: new volumes start empty |
| Environment and service variables, if you choose to | Backup policies |

<Steps>
<Step>

### Open the source environment's menu [#open-the-source-environments-menu]

Open the project, select the environment to copy, then select its settings icon and **Duplicate…**.

</Step>
<Step>

### Name the copy [#name-the-copy]

**Copy from** shows the source; change it if needed. Enter a **Name** such as `Staging` and pick the **Kind**. Select **Continue**.

![The Name the copy step of the Duplicate environment wizard, copying from Production](/screens/environment-duplicate.webp)

</Step>
<Step>

### Choose what comes over [#choose-what-comes-over]

Under **What comes over**, pick **Copy variables** or **Start without variables**. Copied secrets stay encrypted. Start without variables when the copy must not reach the source's databases or APIs. Select **Continue**.

</Step>
<Step>

### Review and duplicate [#review-and-duplicate]

Check the summary and select **Duplicate environment**. The project opens on the new environment.

</Step>
<Step>

### Add domains and deploy [#add-domains-and-deploy]

Nothing is deployed yet. Point variables such as `DATABASE_URL` at the copy's own database, add [domains](../networking/domains.mdx), then select **Deploy** on each service.

</Step>
</Steps>

Secrets are copied only if you can read them in the source environment. Otherwise the copy lists each one as a warning and you set it on the new service's **Environment** tab.

<Callout type="info">
Each environment gets its own volumes and databases. Duplicating copies the configuration, not the data. To copy data, restore a backup into the new database. See [Restore](../data/restore.mdx).
</Callout>

### With the API [#with-the-api]

`POST /api/environments/{id}/duplicate` does the same; over MCP it is the `environment_duplicate` tool. A name already taken in the project returns `409`, and a copy that fails halfway is removed, so retrying is safe.

```bash title="Duplicate Production into Staging"
curl -fsS -X POST "https://stack.example.com/api/environments/env_storefront_production/duplicate" \
  -H "x-api-key: $LOGISTACK_API_KEY" \
  -H "content-type: application/json" \
  -d '{ "name": "Staging", "kind": "staging", "includeVariables": true }'
```

### Copy with changes, or into another project [#copy-with-changes-or-into-another-project]

To change hostnames or values on the way, or to copy into another project, use a manifest: open the source environment's menu and select **Export manifest**, edit the file, then open the target project's actions menu, select **Import manifest…** and apply it to the target environment. Secret values are never exported, so set them after applying. See [Project manifests](../automation/project-manifests.mdx).

## Common problems [#common-problems]

- **A service in one environment can't reach another's database**: by design. Each environment has its own network. Put both services in the same environment.
- **The import reports a name that matches nothing**: the manifest names a Git provider, S3 destination, DNS provider or certificate that doesn't exist in this organization. Create it, or fix the name.
- **The copy's services don't start**: duplicating or applying a manifest doesn't deploy. Select **Deploy** on each service.
- **"This project already has an environment with that name"**: environment names map to unique slugs within a project. Pick another name.
