How to Set Up a Staging Environment on DigitalOcean App Platform

intermediate 8 min read Updated 2026-03-24
Quick Answer

Set up a staging environment by creating a dedicated project tagged as Staging in the DigitalOcean Control Panel, deploying a separate app linked to that project, and configuring environment-specific variables like APP_ENV=staging and database connections. Each environment runs as an independent app for clean resource isolation and separate deployments.

Get DigitalOcean App PlatformPartner

Prerequisites

  • DigitalOcean account with App Platform access and active billing
  • Existing production app or GitHub repository ready for deployment
  • doctl CLI installed and authenticated via doctl auth init
  • Separate managed database instance or external service for staging data
  • Git repository with develop or staging branch for auto-deploy configuration

Step-by-Step Instructions

1

Install and Authenticate doctl CLI

Download the doctl command-line tool from your DigitalOcean Control Panel under API > Tokens & Keys. Run the authentication command to connect your local environment to your DigitalOcean account:

doctl auth init

When prompted, enter your API token. This enables you to create projects and apps via terminal commands with full precision and automation capabilities.

Store your API token securely and never commit it to version control.
2

Create a Staging Project via UI

Log in to the DigitalOcean Control Panel at cloud.digitalocean.com and navigate to the main Dashboard. Click the New Project button to open the project creation form. In the Environment dropdown, select Staging to tag this project for your staging environment. Enter a descriptive project name like myapp-staging-project and a purpose such as Staging environment for myapp. Click Create Project to finalize. The project now appears in your project list with the Staging environment tag.

Use consistent naming conventions with hyphens (e.g., myapp-staging-project) for easier identification across environments.
3

Create a Staging Project via CLI (Alternative)

For precision and automation, create your staging project using the doctl command:

doctl projects create --name "myapp-staging-project" --purpose "Staging environment for myapp" --environment "Staging"

The command returns a project ID (e.g., c4f2b0a8-6f17-4e6f-9b8f-1a2b3c4d5e6f) that you will need for subsequent app creation steps. Note this ID for later use in linking your staging app to this project.

Copy the project ID immediately after creation to avoid searching for it later.
4

Prepare Your App Specification File

Create a my-staging-app.yaml file in your repository root with your application configuration. This file defines services, environment variables, and deployment settings specific to staging:

name: myapp-staging services: - name: web source_dir: / github: repo: yourusername/yourrepo branch: staging envs: - key: DB_HOST value: staging-db.example.com - key: API_URL value: https://staging-api.example.com - key: APP_ENV value: staging

Connect the app to your staging Git branch (e.g., staging or develop) and set staging-specific environment variables for database hosts, API endpoints, and application environment flags. Sensitive variables can be encrypted via the UI after deployment.

Use staging-specific database hosts and API URLs to prevent accidental data corruption or service calls to production systems.
5

Deploy the Staging App via CLI

Deploy your staging app using the specification file and link it to your staging project:

doctl apps create --spec /path/to/my-staging-app.yaml --project-id "c4f2b0a8-6f17-4e6f-9b8f-1a2b3c4d5e6f"

Replace the spec path with your actual file location and the project ID with the one from your staging project creation. The command returns an app ID (e.g., 01c03d96-43bb-4da9-ba54-0b215c44a498) confirming that your staging app is now organizationally linked to the Staging environment and ready for deployment.

Verify the app ID in the output to confirm successful creation before proceeding to configuration.
6

Deploy the Staging App via UI (Alternative)

In the DigitalOcean Control Panel, navigate to your staging project and click Create App. Select your GitHub repository and choose the staging or develop branch for auto-deployment. In the app creation wizard, update the app name to something like myapp-staging. Proceed through the configuration steps, ensuring your app is linked to the staging project. This UI-based approach provides visual confirmation at each step and is ideal for users less familiar with CLI tools.

Enable auto-deploy on the staging branch to automatically redeploy when code is pushed.
7

Configure Environment Variables

In the App Platform dashboard, navigate to your staging app and open Settings > Environment Variables. Define staging-specific variables that differ from production, such as:

DB_HOST=staging-db.example.com API_URL=https://staging-api.example.com APP_ENV=staging NODE_ENV=staging

For sensitive values like database passwords or API keys, use the encrypted variable option in the UI. These variables ensure your staging app connects to staging databases and services rather than production systems, maintaining clean isolation between environments.

Document all environment variables in a team wiki or README to ensure consistency across deployments.
8

Set Up Staging Database

Create a separate managed database instance for staging or use a distinct database within an existing cluster. In the App Platform dashboard, navigate to your staging app's Resources tab and add a managed database connection. Configure the connection string to point to your staging database host. If you need production-like data for testing, carefully sync a recent dump from production to staging, but ensure you disable any automated email sending or external service triggers to prevent accidental notifications to real users.

Use a staging database with a clear naming convention (e.g., myapp-staging-db) to prevent accidental connections to production.
9

Enable Auto-Deploy for Staging Branch

In your staging app's Settings tab, enable Auto-deploy and configure it to trigger on pushes to your staging or develop branch. This automation ensures that every code change pushed to the staging branch automatically redeploys to your staging environment without manual intervention. Disable auto-deploy for your production app to maintain control over production deployments and prevent accidental pushes from automatically going live.

Use branch protection rules in GitHub to require code reviews before merging to the staging branch.
10

Test Staging Environment and Verify Configuration

Access your staging app using its assigned domain (e.g., myapp-staging.ondigitalocean.app) and verify that all features work correctly with staging-specific configurations. Check that database connections point to staging databases, API calls use staging endpoints, and environment variables are correctly loaded. Monitor the app logs in the App Platform dashboard to identify any configuration errors or missing variables. Run your test suite against the staging environment to ensure feature parity with production before deploying to live users.

Use a staging subdomain like staging.example.com and restrict access with password protection or IP rules to prevent public indexing.

Common Issues & Troubleshooting

Environment variables not loading correctly in staging app

Verify that all environment variable names match exactly in your app specification file and the App Platform dashboard. Check that sensitive variables are properly encrypted and that the app has been redeployed after variable changes. Use the app logs to confirm which variables are being read at startup.

Staging app connecting to production database instead of staging database

Double-check the DB_HOST environment variable in your staging app settings to ensure it points to the staging database host, not production. Verify the database connection string in your application code uses the APP_ENV or NODE_ENV variable to load the correct database configuration. Test the database connection manually using a database client to confirm connectivity.

Project ID error when deploying app via CLI

Confirm that the project ID from your staging project creation command is correct and complete. Run doctl projects list to retrieve the correct project ID if needed. Ensure there are no extra spaces or special characters in the project ID when passing it to the doctl apps create command.

Auto-deploy not triggering when pushing to staging branch

Verify that auto-deploy is enabled in the staging app's Settings tab and that the branch name matches exactly (e.g., staging vs develop). Check that your GitHub repository is properly connected to App Platform and that you have push permissions. Review the app's deployment history in the dashboard to see if deployments are being triggered.

Staging app deployment fails with spec file errors

Validate your YAML specification file syntax using an online YAML validator. Ensure all indentation is correct and that environment variable keys and values are properly quoted. Check that the GitHub repository path and branch name in the spec file are accurate and that the repository is accessible to your DigitalOcean account.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official DigitalOcean App Platform website before purchasing.
Special Offer

Affiliate link. We may earn a commission at no extra cost to you.