# Deployment

This checklist covers deploying Turista to a production environment.

## Pre-deployment

- [ ] Set `APP_ENV=production`.
- [ ] Set `APP_DEBUG=false`.
- [ ] Set a strong `APP_KEY` (`php artisan key:generate`).
- [ ] Configure MySQL credentials.
- [ ] Set `REQUEST_DOCS_ENABLED=false`.
- [ ] Restrict `CORS_ALLOWED_ORIGINS` to known frontend domains.
- [ ] Configure Sanctum stateful domains if using cookie-based SPA auth.
- [ ] Configure mail/SMS/WhatsApp providers (CoreVerde).
- [ ] Set up queue connection (database or Redis).
- [ ] Set up scheduler cron entry.

## Build steps

1. **Install dependencies**

   ```bash
   composer install --no-dev --optimize-autoloader
   npm ci
   npm run build
   ```

2. **Run migrations**

   ```bash
   php artisan migrate --force
   ```

3. **Cache Laravel optimizations**

   ```bash
   php artisan config:cache
   php artisan route:cache
   php artisan view:cache
   php artisan optimize
   ```

4. **Create storage link**

   ```bash
   php artisan storage:link
   ```

5. **Set directory permissions**

   Ensure `storage/` and `bootstrap/cache/` are writable by the web server.

## Scheduler and queues

Add the scheduler cron entry:

```cron
* * * * * cd /path/to/turista && php artisan schedule:run >> /dev/null 2>&1
```

Run a queue worker using Supervisor or systemd:

```bash
php artisan queue:work --sleep=3 --tries=3 --max-time=3600
```

## Web server

Point the document root to `public/`. Use HTTPS in production.

## Post-deployment verification

- [ ] Health check returns `200 OK` on `/`.
- [ ] Login endpoint returns a token for valid credentials.
- [ ] Migrations completed without errors.
- [ ] Queue worker is processing jobs.
- [ ] Scheduler is running every minute.
- [ ] Logs are being written to `storage/logs/`.

## Rollback

If a deployment fails:

1. Restore the previous code version.
2. Run `php artisan migrate:rollback` if migrations were applied.
3. Clear caches: `php artisan optimize:clear`.
4. Re-run `php artisan optimize`.
