# Local Environment — Live Database Clone Safely

## Goal

Bring the site to local using a snapshot/copy of the production database for development and debugging.

## Safety

Never:
- connect local code to production DB for normal development
- commit production credentials
- commit `.env`
- expose production payment/API secrets locally
- send real customer messages/emails/SMS from local
- accidentally trigger production cron jobs

## Required local environment isolation

Set:
- `APP_ENV=local`
- `APP_DEBUG=true` locally only
- local database
- local queue
- local cache
- local mail catcher/log driver
- fake/sandbox payment integration
- local storage

Disable or mock:
- production SMS
- production email delivery
- production payment gateway
- production webhooks
- production cron/schedulers where they can cause side effects

## Database import

Use a sanitized production snapshot where possible.

Recommended sequence:
1. backup current local DB
2. create fresh local DB
3. import snapshot
4. run required migrations
5. verify schema compatibility
6. run application boot
7. fix environment-specific assumptions

## Data privacy

Customer/order data may exist in a production snapshot.

Restrict local access.

Where practical, anonymize:
- passwords only if authentication testing permits
- personal names
- phone numbers
- emails
- addresses
- payment tokens/secrets

Never alter business identifiers in a way that breaks relational integrity.

## Storage

Copy product/blog assets needed for local testing.

Use local storage path.

Verify:
`php artisan storage:link`

## Cache/session/queue

Clear local state:
- config cache
- route cache if applicable
- view cache
- application cache
- sessions

Start local workers only for queues that are safe to execute.

## Verification

After boot:
- homepage
- login
- product
- category
- cart
- checkout in sandbox/mock mode
- admin
- blog
- menu manager

All must use local services only.

## Deployment preparation

When features are validated:
- create migrations
- create release notes
- list environment changes
- list commands
- list cache-clearing needs
- list backfills
- list rollback strategy

Do not deploy database changes without a rollback/data-migration plan where appropriate.
