Local, Staging, Production: Why Apps Have Multiple Environments
Why developers run the same app in local, staging and production environments, what each one is for, and how to keep them safely separated.
In this article
If you have worked with developers, you have probably heard sentences like "it works on local", "let's push it to staging" or "don't touch production". These are the names of environments: separate copies of the same app, each with its own purpose.
Understanding environments explains why changes are not live the moment a developer finishes coding, and why that is a good thing.
What Is an Environment?
An environment is a complete place where an app runs: its code, settings, database, and the server or computer it runs on.
Most teams use at least three:
- Local (development): the developer's own computer.
- Staging: a private copy of the live site used for final testing.
- Production: the real, live app that customers use.
In simple words: environments let you practise safely before you perform in public.
A Simple Analogy
Think of a theatre play:
- Local is rehearsing lines at home. Mistakes cost nothing.
- Staging is the dress rehearsal on the real stage, with lights and costumes, but no audience.
- Production is opening night. Everything must work, because people are watching.
The Local Environment
This is where code is written. The app runs on the developer's laptop at an address like http://localhost:8000.
- Uses a small, fake or copied database.
- Shows detailed error messages to help debugging.
- Emails are usually caught by a tool like Mailpit instead of being sent.
- Breaking things here is expected and harmless.
The Staging Environment
Staging is a copy of production that lives on a real server, often at an address like staging.example.com. It should be as close to production as possible: same server type, same PHP or Node version, same configuration, similar data.
Staging is where teams:
- Test new features before release.
- Let clients or product managers review and approve changes.
- Run final automated tests.
- Try database migrations on realistic data.
Staging should be password-protected or blocked from search engines, so customers and Google never see half-finished work.
The Production Environment
Production is the real thing. It has real users, real payments and real data. Here:
- Error details are hidden from visitors and sent to logging tools instead.
- Performance settings like caching are switched on.
- Only tested code gets deployed, usually through an automated pipeline.
- Changes are made carefully, often during low-traffic hours, with a way to roll back.
How the Same Code Behaves Differently
The code is the same in every environment. What changes is the configuration, usually stored in a .env file:
# Local .env
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000
DB_DATABASE=myapp_local
MAIL_MAILER=log
# Production .env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com
DB_DATABASE=myapp_live
MAIL_MAILER=smtp
Same code, different settings. This is why you never copy a local .env file to a live server: debug mode would expose sensitive details to the public.
The Typical Flow of a Change
- A developer builds the feature locally and tests it.
- The code is pushed to Git and reviewed.
- A CI/CD pipeline runs tests and deploys it to staging.
- The team checks it on staging.
- Once approved, the same code is deployed to production.
Because the code passes through each stage in order, most bugs are caught before customers ever see them.
Other Environments You May Hear About
- Testing / QA: a dedicated environment for testers, separate from staging.
- Preview environments: temporary copies created for each pull request, common on platforms like Vercel and Netlify.
- UAT (User Acceptance Testing): an environment where the client signs off on features.
Small teams often combine these into one staging site. That is fine, as long as nothing is tested directly on production.
Common Mistakes to Avoid
- Testing on production. Even a "tiny fix" can break checkout for real customers.
- Staging that doesn't match production. If staging runs PHP 8.2 and production runs 8.4, a passing test means very little.
- Using real customer data locally without anonymising it. This can break privacy laws.
- Leaving staging public and indexable. Google may index it, creating duplicate content and confusing visitors.
- Sharing one database between environments. A test on staging could delete live orders.
- Debug mode left on in production, which can leak passwords and file paths in error pages.
Environments FAQ
Do small projects really need a staging environment?
For a personal blog, maybe not. For anything that takes payments, stores user data or has a client, yes. A cheap staging server costs far less than a broken live site.
What does "deploy to production" mean?
It means copying the tested code to the live server and switching users over to the new version.
What is the difference between staging and testing environments?
A testing environment is mainly for automated or QA tests and may contain fake data. Staging is the final, production-like rehearsal before release.
How do I keep staging out of Google?
Protect it with a password, or send a noindex header from the staging server. Blocking it only in robots.txt is not enough on its own.
Key Takeaway
Local is for building, staging is for checking, and production is for customers. Keeping them separate, with different settings in each .env file, is what lets teams ship changes without breaking the live app.
Mini Cheat Sheet
- Local: your laptop, debug on, fake data
- Staging: production copy, private, final testing
- Production: live users, debug off, real data
- .env: where each environment's settings live
Try it: Create a commented, production-ready configuration file with our free .env file generator, then read What Is a .env File? to understand each setting.
Join the conversation
What do you think?
Write a comment
No comments yet. Be the first to share a thought.