Hetzner Staging and Production Workflow: A Practical Setup

Hetzner Staging and Production Workflow: A Practical Setup

A staging and production workflow on Hetzner means running two isolated environments and promoting only tested changes from staging to production. The simplest reliable version uses two separate servers, or two isolated stacks on one server with separate folders, databases, and credentials. Staging is where you test, break things, and verify fixes; production is what your users see, and it should only receive changes that passed staging.

Why Separate Staging from Production

Deploying directly to production introduces avoidable risks, especially when configuration changes, dependency updates, or database migrations are involved. A staging environment gives those changes somewhere to fail safely first. It also supports real quality checks: a production-parity staging environment is where performance testing, regression testing, and user acceptance testing happen before release.

The risk is concrete. Copying one environment over another without care risks data loss, overwriting live transactions, or breaking integrations. Production may already contain new orders, user registrations, or fresh content that staging does not have, which complicates any synchronization attempt. Testing against live data is how teams accidentally email real customers, charge real cards, or delete real records.

There is also an operational benefit. Version control provides accountability, reproducibility, and rollback capability for deployments. When every change reaches production through a tracked path, you know who changed what and can revert a problematic release.

Choosing Your Architecture on Hetzner

You have three realistic options, and the right one depends on team size, budget, and how much risk you can tolerate.

Two Separate Servers

This is the clearest separation: one Hetzner server for staging, one for production. A described Hetzner production setup used a single staging server for development and testing alongside its production fleet. The advantage is hard isolation: a staging mistake cannot touch production files, databases, or processes. The cost is a second server to pay for and maintain.

One Server with Isolation

Staging and production can live on the same hosting account but should not share the same folder, database, or environment settings. On a single Hetzner server, that means separate document roots or containers, separate databases, and separate configuration files. This is cheaper and fine for small projects, but it concentrates risk: a server-level failure or a misconfigured web server rule can affect both environments at once.

Hybrid and Multi-Provider Setups

Staging and production do not have to sit on the same provider. A dual-environment example runs production on AWS and staging on Hetzner Cloud, showing the two can live on different infrastructure. This can make sense when production has managed services you depend on while staging stays inexpensive.

Networking and Access Isolation

If you run multiple Hetzner servers, isolate them. A Hetzner architecture can place application servers on a private network with only a bastion host exposed for SSH access. One critical detail: Hetzner Cloud Firewalls do not filter traffic between servers on the same private network, so host-based firewalls are essential. Private networking is not a substitute for securing each host.

Architecture Comparison

Option Isolation Cost Operational Complexity Best For
Two separate servers Strong Higher Moderate Teams that need hard separation
One server, isolated stacks Moderate Lower Lower initially, riskier long term Solo developers and small projects
Hybrid or multi-provider Varies Varies Highest Teams with existing managed production services

How Changes Move from Staging to Production

Promotion should be one-way: staging to production, never the reverse for code. A simple branch flow moves work from a feature branch to staging, then to main, then to production. Each step is a gate where something can be rejected.

Automation levels can differ by environment. One Hetzner deployment issue describes staging auto-deploying on push to main while production uses a manual workflow trigger. That pattern is a reasonable default: staging stays fast and low-ceremony, while production requires a deliberate human action.

Avoid the shortcuts that undermine the flow. Manual database edits, SFTP uploads, and one-off plugin updates made directly in production create configuration drift, where environments diverge and bugs become hard to trace. If a fix only exists on the production server, you have lost reproducibility and your next deploy may silently undo it.

Environment drift also appears through mismatched runtime details such as PHP versions, missing extensions, or cache differences. Keeping environments as similar as possible reduces unexpected failures during deployment.

Handling Databases and Uploads Safely

Databases should be separated by environment, and production secrets should never enter development or previews. Staging gets its own database, always. The tempting shortcut of pointing staging at a copy of the live database creates two problems: staging writes can pollute real data, and real customer data ends up somewhere with weaker controls.

When staging needs realistic data, use production-like staging data that is synthetic, masked, anonymized, or explicitly approved. Anonymization matters beyond tidiness; it limits what a staging compromise exposes.

For uploads and generated files, treat staging storage as disposable and separate from production storage. Never sync files from staging to production as part of a deploy, because deletions and test artifacts will travel with them.

Backups are non-negotiable. Both staging and production should be backed up before deploying, because data loss in either can disrupt your workflow. A backup you have never restored is a guess, so test a restore at least once before you need it.

Access Control and Secrets

Staging and production often need different API keys, database credentials, cache settings, debug modes, and email services. Staging should never send real transactional email or hit live payment endpoints. Point it at sandbox or test credentials, and make that separation explicit in configuration rather than in someone's memory.

Sensitive environment files should never be committed to version control; use a safe reference template instead. A committed .env is a permanent leak, even after deletion, because history keeps it. Store real values in your server environment or a secrets store.

One working pattern from a Hetzner deployment issue: secrets are stored in GitHub Secrets rather than in the checked-in compose file. The compose file can live in the repository because it contains no credentials.

Harden both servers, not just production. A Hetzner VPS setup guide recommends creating a non-root deploy user and disabling root SSH login for production hosting. It also recommends SSH key authentication with password authentication disabled, a firewall that denies incoming traffic by default and allows only required ports, and automatic security updates. For web serving, Nginx as a reverse proxy with Certbot for SSL certificates is a common baseline. Restrict production SSH to your team, and consider routing it through a bastion as described above.

A Minimal Starting Workflow

You can start small and tighten later. This sequence works for a solo developer or a small team.

  1. Provision two environments. Either two Hetzner servers or two isolated stacks on one server, with separate folders, databases, and environment settings.
  2. Set up branch-based promotion. Feature branch to staging, staging to main, main to production. Protect main so changes arrive through review.
  3. Automate staging, gate production. Auto-deploy staging on push to main; trigger production manually.
  4. Separate credentials. Distinct API keys, database credentials, debug modes, and email services per environment, stored outside version control.
  5. Harden both hosts. Non-root deploy user, key-only SSH, default-deny firewall, automatic security updates.
  6. Back up before every deploy. Cover both environments.
  7. Define rollback before release. Every release should have a rollback plan before it goes live, and post-deployment monitoring is part of deployment, not optional cleanup.

Common Mistakes to Avoid

  • Editing production by hand. Manual database edits and SFTP uploads create configuration drift and make bugs hard to trace.
  • Letting staging reach live services. Shared API keys and email services mean test actions hit real systems.
  • Overwriting production data during sync. Copying environments carelessly risks data loss and broken integrations, especially when production has newer orders, signups, or content.
  • Skipping backups because a deploy "looks small." Data loss in either environment disrupts the workflow.
  • Treating monitoring as optional. It is part of deployment, along with the rollback plan.
  • Trusting private networking alone. Host-based firewalls remain essential on Hetzner private networks.

Conclusion

Pick the simplest architecture that genuinely isolates production, then tighten the promotion step over time. For most small teams on Hetzner, that means two environments with separate folders, databases, and credentials, one-way promotion through version control, automation on staging with a manual gate on production, and backups plus a rollback plan before every release. Get those basics right and the workflow will scale with your project without becoming a second job.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top