Deployment Guide

AI Prompt Template

Help me deploy a production server.
- Site Type: [Static/PHP/Node.js/Python]
- Server OS: [Ubuntu/CentOS/Debian]
- Database: [MySQL/PostgreSQL/SQLite]
- HTTPS: [Yes/No]

Output: server init, Nginx config, runtime installation, database setup, SSL cert.

Docker Compose for LAMP Stack

version: '3.8'
services:
  web:
    image: nginx:alpine
    ports: ["80:80", "443:443"]
    volumes: ["./site:/usr/share/nginx/html"]
  db:
    image: mariadb:10
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    volumes: ["db_data:/var/lib/mysql"]
volumes: {db_data:}

SSL Certificate with Certbot

apt install certbot python3-certbot-nginx -y
certbot --nginx -d example.com -d www.example.com
certbot renew --dry-run

Deployment Is More Than Uploading Files

"It works on my machine" — these words haunt every ops engineer. The differences between local and production environments cause some of the hardest-to-diagnose production issues.

The goal of deployment isn't "put code on a server." It's "create a predictable, repeatable runtime environment."

Environment Management Principles

1. Consistency

Minimize differences between dev, staging, and production. A single minor version difference in PHP can change function behavior.

Do this: Define your local environment with Docker Compose or Vagrant so anyone can be running in 10 minutes.

2. Configuration Separation

Code and configuration are different things. Database passwords and API keys don't belong in repositories.

project/
├── .env.example        # committed, contains all keys as templates
├── .env                # gitignored, actual values
├── config/
│   ├── app.php
│   └── database.php    # reads from .env

3. Rollback Capability

Every deployment should be rollbackable within 5 minutes. If yours isn't, you're gambling.

Deployment Strategy Comparison

Strategy Downtime Complexity Use Case
Direct replace Yes Low Personal projects, low traffic
Blue-green No Medium Business sites, production
Rolling update No Medium Multi-instance clusters
Canary No High High-traffic critical services

For small to medium sites, blue-green is the sweet spot: maintain two environments, deploy to green, validate, switch traffic. If something goes wrong, switch back to blue.

Backup Reality Check

Backups are only as valuable as your ability to restore from them.

Data Type Frequency Retention Restore Drill
Database Daily full + hourly incremental 30 days Monthly
File assets Daily snapshot 7 days Quarterly
Config files Every change Git history forever Not needed

Critical advice: Don't wait for a disaster to test your backups. Run a monthly restore drill on a clean server and verify data integrity. You might be surprised how many backups fail to restore.

SSL Reality

Let's Encrypt certificates are sufficient for most sites. Configure auto-renewal with Certbot, set up monitoring to verify renewal succeeded, and check certificate status monthly. This prevents the panicked "our cert expired!" discovery a year later.