When you clone an app to create a staging environment, you start with a complete copy of production's components, build settings, and most configuration. That saves a manual rebuild, but it also copies what makes production dangerous: database attachments, secrets, domains, and live integrations. The clone is not staging until you change those.
This guide walks through the whole sequence: choosing what to clone, renaming the copy, re-pointing its database, rotating credentials, separating domains and access, and proving with a smoke test that staging cannot reach live data.
Table of Contents
- Decide what the clone must change
- Clone and rename the app configuration
- Re-point data services to a staging database
- Rotate secrets and third-party credentials
- Move domains, DNS, and access controls
- Run a post-clone smoke test
- Conclusion
Decide what the clone must change
There are three common ways to get a staging URL on a PaaS. Pick the one that matches how production-like your tests need to be.
| Approach | What you get | Best for | Watch out for |
|---|---|---|---|
| Full configuration clone | A new app with copied components, build settings, environment variables, and database configuration | Like-for-like staging of an existing app | Copied production settings, data attachments, and secrets |
| Branch-based deploy | The same app, or a preview app, deployed from a staging branch | Quick code review and feature previews | Often shares environment variables, database, domain, and logs with production |
| Fresh environment from an app spec | A clean app defined from a YAML spec | Strong isolation and repeatable rebuilds | More setup, and drift unless the spec is maintained |
For most teams, the full clone is the right starting point when the goal is "staging that behaves like production." Azure App Service uses a related pattern: deployment slots are live apps with their own host names, and you can clone settings from an existing slot before swapping traffic. Platforms differ in mechanics, but the idea is the same: copy the configuration, then give the copy its own identity. The Azure deployment slots documentation explains what gets cloned and what stays slot-specific.
Staging exists to catch deployment and integration problems before users see them. The roles each environment plays, and the isolation each one needs, are covered in these best practices for separating development, staging, and production environments. Use that as the design rule: staging should match production in behavior, not in blast radius.
At minimum, these settings must differ between the clone and production.
| Setting | Production | Staging |
|---|---|---|
| Source branch | main | staging or a release candidate |
| Database | Production cluster | Separate staging cluster or dev database |
| Secrets | Live third-party keys | Test or sandbox keys |
| Object storage | Production bucket | Staging bucket |
| Custom domain | app.example.com | staging.example.com |
| Webhooks and callbacks | Live endpoints | Staging endpoints |
| Scale | Production instance counts | Smaller instance counts |
| Logs and alerts | On-call channel | Staging channel |
| Access | Public or limited | SSO, IP allowlist, or basic auth |
Identity isolation matters as much as data isolation. OWASP warns that reusing the same service accounts or API keys across environments lets an attacker who compromises a weaker test environment reach production resources. Its guidance is to assign unique identities to each environment and grant each one only the permissions it needs. The OWASP environment isolation guidance for non-human identities explains the risk and the controls.
Clone and rename the app configuration
Set the clone up correctly in the clone screen itself. On App Platform, the cloned app deploys automatically when you finish, using the settings you selected. A clone that starts with the production branch and production database attached is a second production until you fix it.
- Start the clone. Open the Apps page, select the production app, open the Actions menu, and choose Clone app.
- Rename every component. Change
webtoweb-staging,apitoapi-staging, and so on. Component names appear in logs, internal DNS, and bindable variable prefixes, so clear names prevent cross-environment confusion. - Change the branch. Point each component at your staging branch instead of
main. Decide whetherdeploy_on_pushshould be on for that branch; automatic deploys are useful for staging, but only if the branch is protected. - Right-size the copy. Lower instance counts and instance sizes where staging does not need production capacity, but leave enough memory and CPU for migrations, background jobs, and end-to-end tests.
- Choose the project and environment. Put the clone in a staging project or environment so billing, access, and deployment history stay attributable. Use a unique app name that includes
-stagingor your environment suffix. - Review region and VPC settings. The clone copies the datacenter region and VPC network setting from the original app. Keep them if staging must reach shared private services; choose a different region only when staging serves a different user base or has data residency constraints.
App Platform's guide to cloning apps documents the full flow. It also notes two details that matter for staging: database configuration is copied from the original, and app-level environment variables are copied except for encrypted values, which must be re-entered. Treat both as work items, not as conveniences.
Use a short checklist before you leave the clone screen:
- [ ] App name and project identify the environment
- [ ] Every component name includes the staging suffix
- [ ] Branch points to staging, not
main - [ ] Instance sizes and counts are reduced
- [ ] Region and VPC choice is deliberate
- [ ] Database replacement and secret re-entry are planned
Re-point data services to a staging database
The copied database configuration is the most dangerous default in a clone. Replace it before the first boot, especially if your app runs migrations or seeds data at startup.
- Create the staging database first. Use a dev database for lightweight tests or a managed database when staging needs realistic performance, backups, and scaling. App Platform recommends managed databases for production use, and its guide to managing databases in App Platform explains the differences between dev and managed options.
- Delete the copied database configuration. In the clone screen, remove the database component inherited from production.
- Attach the staging database. When you add a dev or managed database, App Platform updates the connection environment variables automatically and, when trusted sources are enabled, adds the app as a trusted source.
- Update external database settings yourself. If you use a database outside App Platform, set the host, port, user, password, and database name on every component, worker, and job that connects. Component-level variables override app-level variables, so check each one.
- Verify the target before migrations run. Open the app console and print
DATABASE_URL. Confirm the host and database name belong to staging. If the app and database share a VPC, also checkDATABASE_PRIVATE_URL, which uses the private endpoint instead of the public connection string. - Seed with safe data. Do not restore a raw production dump. OWASP's guidance on protecting data across environments recommends masking, anonymizing, or synthesizing production data so staging never contains real personal information.
- Search for leftovers. Check custom variables for production database hosts, replica URLs, and read-only endpoints. A forgotten analytics replica is still a production data path.
These are the connection settings worth inspecting in every component:
| Variable | What to confirm |
|---|---|
DATABASE_URL | Host, database name, and user belong to staging |
DATABASE_PRIVATE_URL | Uses the staging private endpoint when both run in the same VPC |
REDIS_URL | Points to a staging cache, not the production cache |
CA_CERT | Matches the staging database cluster |
Custom S3_*, SMTP_*, or PAYMENT_* values | Point to staging services and scoped credentials |
Rotate secrets and third-party credentials
Do not assume a copied secret is safe. Re-enter every sensitive value and replace it with a credential created for staging.
App Platform can store sensitive variables as encrypted values, and the encryption option hides them from build, deployment, and application logs. The platform's guide to environment variables in App Platform also notes an important limit: encrypted values are decrypted at runtime, so trusted team members who can open the console or edit the app can still view them. Encryption protects logs and casual exposure, not a compromised teammate account.
OWASP's secrets management guidance is direct: use separate credentials per environment, never share a production credential with staging or development, and prefer a secret manager or dynamic credentials over long-lived static values. Apply that rule integration by integration.
| Integration | Staging setting |
|---|---|
| Payments | Sandbox or test keys, plus a test webhook secret |
| Sandbox service or capture inbox; suppress real recipients | |
| SMS | Provider test numbers or a sandbox |
| OAuth and SSO | A separate staging client ID, secret, and callback URL |
| Webhooks | https://staging.example.com/webhooks/... with a staging signing secret |
| Analytics | A staging property, or disable collection |
| Cloud storage | A staging bucket and credentials scoped to that bucket |
Also review the values that are easy to overlook: feature flag API keys, error tracking projects, CDN tokens, search indexes, and queue connection strings. A staging app that writes to the production error tracker or search index is still contaminating production.
Use the platform's encrypted-variable option for anything sensitive, and keep secrets out of the repository and out of build-time variables unless the build genuinely needs them. If your provider supports workload identity or OIDC for CI/CD, prefer short-lived credentials over stored keys.
Move domains, DNS, and access controls
Every App Platform app gets a starter domain on ondigitalocean.app after deployment. You can add a custom domain, but DNS changes can take up to 72 hours to propagate, so plan the cutover rather than discovering it during a release. The App Platform domain management guide covers both DigitalOcean-managed DNS and CNAME-based setups.
- Use the starter domain or a staging subdomain. Keep the generated
ondigitalocean.appURL, or addstaging.example.com. Do not attach the production hostname such asapp.example.comto the clone. - Remove inherited production domains. Check the clone's Networking tab and remove any custom domain that points at the live site. A hostname should route to one app, and that app should be the one you intend.
- Update app URLs. Set
APP_URL, frontend API base URLs, and OAuth callback URLs to the staging hostname. If you use the bindable${APP_URL}value, confirm it resolves to the clone's domain rather than the original app's domain. - Restrict access. Put staging behind SSO, an IP allowlist, or a proxy that enforces basic authentication. Test accounts and test cards still deserve protection, and an open staging site is an easy target for scanners.
- Keep staging out of search. Send an
X-Robots-Tag: noindexheader or serve a disallow-allrobots.txt. A staging site that ranks for production terms creates confused customers and support tickets. - Update CORS and CSP rules. Allow the staging frontend origin and remove production origins from the clone's CORS configuration. Otherwise staging browsers will call production APIs or fail with opaque CORS errors.
- Neutralize outbound messages. Point email, SMS, and push notifications at sandbox services or internal sinks. Add a visible staging banner and set an
APP_ENV=stagingvalue so testers and code paths know which environment they are in.
Run a post-clone smoke test
A clone becomes staging only after you prove it is isolated. Run these checks in order and stop at the first failure.
| Check | How to verify | Pass condition |
|---|---|---|
| Environment identity | Load the home page and admin area; inspect logs | A staging banner appears and APP_ENV is staging |
| Code version | Compare the running commit hash with the branch | Commit matches the staging branch, not main |
| Database target | Print DATABASE_URL in the console; create a test row | Host and database are staging; production row count is unchanged |
| Data safety | Query for production-only records or known customer data | No real production data is present |
| Secrets | Inspect key prefixes, modes, and variable sources | Test or sandbox keys only; no production secrets remain |
| Trigger a signup or password reset to a test address | Message arrives in the sandbox; production inbox receives nothing | |
| Payments | Run a checkout with a test card | Test mode is active and no live charge appears |
| Webhooks | Send a test event from the provider | The staging endpoint receives it with the staging signing secret |
| Auth and permissions | Log in as a staging admin; try a production admin URL | Staging identity has no production access |
| Domains | Resolve the production and staging hostnames | Production still routes to the production app |
| Logs and alerts | Check the configured destination | Staging app name appears in the staging channel |
After the read-only checks pass, run one controlled destructive test: delete a test record, rotate a test key, or replay a webhook. Confirm the change appears only in staging and in the staging provider dashboard. If any action reaches production, stop and fix the isolation before anyone uses the environment.
Keep the smoke test in the repository as a script or checklist and run it whenever you refresh staging from production. Refreshing data is where old production credentials and database attachments tend to sneak back in.
Conclusion
Cloning an app configuration is a shortcut, not a finish line. The clone gives you production's components and settings; staging requires you to change the branch, rename the app and services, replace the database, rotate every secret, separate the domain and access rules, and prove the result cannot reach production data or third-party live endpoints.
Use the clone screen to make as many of those changes as possible before the first deploy, then run the smoke test every time you refresh the environment. A staging environment that is easy to rebuild and hard to confuse with production is worth more than a perfect one-time copy.
