Skip to content

Deployment

Deployment guide for the CPR backend.

Prerequisites

  • PHP 8.2+ with required extensions
  • MySQL 8.4
  • Redis 7
  • Composer
  • Node.js (for building frontend assets)

Production Deployment Steps

1. Pull Latest Code

bash
git pull origin master

2. Install Dependencies

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

3. Run Migrations

bash
php artisan migrate --force

4. Optimize for Production

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

5. Restart Services

bash
# Restart the queue worker
php artisan queue:restart

# Restart your process manager (e.g., Supervisor)
sudo supervisorctl restart all

Environment Configuration

Key production environment variables:

env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-domain.com

DB_CONNECTION=mysql
DB_HOST=your-db-host
DB_DATABASE=cpr_production

CACHE_STORE=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

SANCTUM_STATEFUL_DOMAINS=your-frontend-domain.com
CORS_ALLOWED_ORIGINS=https://your-frontend-domain.com

SENTRY_LARAVEL_DSN=https://your-dsn@sentry.io/project
SENTRY_TRACES_SAMPLE_RATE=0.2

ENABLE_BRANCH_ISOLATION=true
REQUIRE_BRANCH_CONTEXT=true
ENABLE_AUDIT_LOGGING=true

Production Checklist

  • APP_DEBUG must be false
  • APP_ENV must be production
  • CORS origins must be restricted to your frontend domain
  • Sanctum stateful domains must match your frontend domain
  • Sentry DSN must be configured for error tracking
  • Redis must be available for cache, sessions, and queues

Docker Deployment

Using the included compose.yaml:

bash
docker compose up -d
docker compose exec laravel.test php artisan migrate --force
docker compose exec laravel.test php artisan optimize

Services in Docker

ServicePortPurpose
laravel.test80Laravel application
mysql3306Database
redis6379Cache, sessions, queues
mailhog8025Email testing (dev only)

Queue Worker

For production, use Supervisor to keep the queue worker running:

ini
[program:cpr-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/cpr-backend/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/supervisor/cpr-queue.log

Rollback

If a deployment causes issues:

bash
# Rollback the last migration batch
php artisan migrate:rollback

# Clear caches
php artisan optimize:clear

# Revert to the previous code
git checkout <previous-commit>
composer install --optimize-autoloader --no-dev
php artisan optimize

CPR - Clinical Patient Records