noted.do
The Tech Guy

Staging - The Copy of Your Site Nobody Visits

"Works on my machine" is a joke because it's true so often. Your laptop has a different PHP version than the server, a different database setup, files sitting in places production doesn't have, and none of the real traffic. Code that runs perfectly in development can still fall over the moment it's deployed. A staging environment is how you find that out before your users do.

Staging is a second copy of your production setup that isn't public. Same operating system, same web server, same language version, same database engine, same configuration, as close as you can reasonably make it. You deploy to staging first, check that things work, and only then deploy the same code to production.

The point isn't testing your code's logic. Your local setup and your tests handle that. Staging tests the deployment itself. Does the migration actually run against a database shaped like the real one? Did you forget to add that new environment variable on the server? Does the cron job have permission to write to the folder it needs? Is the reverse proxy passing the right headers? These are the bugs that never show up locally and always show up in production.

It's also where other people can look at a change before it's live. If you're building something for a client or a team, a staging link is a much better way to get sign-off than screenshots.

A few things make staging genuinely useful instead of just a box you deploy to out of habit.

Keep it close to production. If production runs on a particular database version behind Nginx in Docker, staging should too. Every difference is a place for a surprise to hide. If you use containers, this gets a lot easier, since you can run the exact same image in both places.

Deploy it the same way. If you deploy to production with a script or a CI pipeline, use that same process for staging. Deploying by hand to one and automatically to the other means you're not really testing the deploy.

Be careful with data. It's tempting to copy the production database into staging so you have realistic content. That's useful, but it means a less-protected server now holds real people's personal information. Better options are generated test data, or a copy where emails, names, addresses and anything sensitive have been scrubbed or replaced.

Stop it from talking to the real world. A staging app with live settings can send emails to actual customers, charge real cards, or fire webhooks at real services. Use test mode keys for payment providers, point outgoing mail at a catch-all inbox tool like Mailpit, and give staging its own separate credentials for everything.

Keep it private. Put it behind a password, an IP allowlist or a VPN, and tell search engines not to index it. A staging site with debug mode on, sitting in public, is a gift to anyone scanning for one.

Do you need staging for a tiny personal site? Probably not. If a typo goes live on your hobby blog, you fix it. But once other people depend on what you've built, or once a bad deploy could lose data or money, a staging environment pays for itself the first time it catches something. And it will catch something.

Comments

Be kind. See the rules.