Deployment
Deployment Overview
Section titled “Deployment Overview”Deployments push code from the main branch on GitHub to the production server via SSH and Git.
Quick Deployment
Section titled “Quick Deployment”# Deploy main branch to productionmake deployThis command:
- SSHs into production server
- Stashes any uncommitted changes
- Checks out
mainbranch - Pulls latest code from GitHub
- Pops stashed changes (if any)
Full Deployment Process
Section titled “Full Deployment Process”1. Pre-Deployment Checklist
Section titled “1. Pre-Deployment Checklist”- Code tested locally
- All tests passing
- Database migrations prepared (if needed)
- No breaking changes to coworker’s workflow
- Coworker notified of deployment
- Backup plan ready
2. Check Current Production State
Section titled “2. Check Current Production State”# Check what's on production servermake status
# Should show:# - Current branch (should be 'main')# - Clean working directory (or pending auto-commits)# - Latest commit3. Review Changes to Deploy
Section titled “3. Review Changes to Deploy”# See what will be deployedgit log origin/main..main --oneline
# Or check GitHubopen "https://github.com/my-marketing-pro/mmp-webapp/commits/main"4. Deploy
Section titled “4. Deploy”# Deploy to productionmake deployWhat happens:
ssh mymarketingpro "cd /var/www/sftp/app && sudo git stash && sudo git checkout main && sudo git pull && sudo git stash pop 2>/dev/null || true"5. Verify Deployment
Section titled “5. Verify Deployment”# Check production statusmake status
# Should show:# - On branch main# - Latest commit matches your local# - No errors6. Test Production
Section titled “6. Test Production”- Open production site in browser
- Test the changed functionality
- Check browser console for errors
- Monitor for any issues
7. Monitor
Section titled “7. Monitor”# SSH into serverssh mymarketingpro
# Check error logssudo tail -f /var/log/nginx/error.logsudo tail -f /var/log/php/error.log
# Check application logscd /var/www/sftp/apptail -f logs/app.log # If you have app loggingDeployment with Database Changes
Section titled “Deployment with Database Changes”If your deployment includes database migrations:
1. Prepare Migration Script
Section titled “1. Prepare Migration Script”Create migration file locally:
-- migrations/2026-01-21-add-user-preferences.sqlALTER TABLE app_usersADD COLUMN preferences JSON NULL AFTER email;
CREATE INDEX idx_user_preferences ON app_users(preferences);2. Test Migration Locally
Section titled “2. Test Migration Locally”# Test on local databasemysql -u root mmp_app < migrations/2026-01-21-add-user-preferences.sql
# Verifymysql -u root mmp_app -e "DESCRIBE app_users;"3. Deploy Code
Section titled “3. Deploy Code”# Deploy application code firstmake deploy4. Run Migration on Production
Section titled “4. Run Migration on Production”# SSH into serverssh mymarketingpro
# Navigate to app directorycd /var/www/sftp/app
# Run migrationmysql -h my-marketing-pro.cluster-c3mws4moov6r.us-east-2.rds.amazonaws.com \ -u admin -p \ mmp_app < migrations/2026-01-21-add-user-preferences.sql
# Verifymysql -h my-marketing-pro.cluster-c3mws4moov6r.us-east-2.rds.amazonaws.com \ -u admin -p \ -e "DESCRIBE mmp_app.app_users;"5. Test Application
Section titled “5. Test Application”Test that the new feature works with the new database structure.
Deployment Scenarios
Section titled “Deployment Scenarios”Scenario 1: Normal Deployment
Section titled “Scenario 1: Normal Deployment”Simple code changes, no database changes, no breaking changes.
make deployScenario 2: Hotfix Deployment
Section titled “Scenario 2: Hotfix Deployment”Critical bug fix that needs to go out immediately.
# Make fix locallygit add .git commit -m "Hotfix: Fix critical authentication bug"git push origin main
# Deploy immediatelymake deploy
# Verify fixopen "https://production-url.com"Scenario 3: Coordinated Deployment
Section titled “Scenario 3: Coordinated Deployment”Large changes that require coworker to pause FTP edits.
- Notify coworker: “Deploying in 10 minutes, please save your work”
- Wait for confirmation: Ensure no active FTP edits
- Deploy:
make deploy- Verify and notify: “Deployment complete, safe to resume”
Scenario 4: Rollback Deployment
Section titled “Scenario 4: Rollback Deployment”Something broke, need to rollback.
# Find last good commitgit log --oneline -10
# Rollback locallygit reset --hard <last-good-commit>
# Force push (careful!)git push origin main --force
# Deploy the rollbackmake deployScenario 5: Deployment with Downtime
Section titled “Scenario 5: Deployment with Downtime”Changes that require brief downtime.
- Put up maintenance page (if you have one)
- Make changes
- Deploy
- Verify
- Remove maintenance page
Deployment Best Practices
Section titled “Deployment Best Practices”Timing
Section titled “Timing”Best times to deploy:
- Low-traffic periods (early morning, late evening)
- Weekdays (not Friday!)
- When coworker is available for coordination
Avoid deploying:
- During peak usage hours
- Friday afternoons (weekend issues)
- When coworker is actively editing via FTP
- Late at night when you can’t monitor
Communication
Section titled “Communication”Before deployment:
- Review changes with team
- Notify coworker of deployment window
- Prepare rollback plan
During deployment:
- Monitor logs
- Test immediately after deployment
- Keep team updated
After deployment:
- Confirm successful deployment
- Monitor for issues
- Document any problems
Safety
Section titled “Safety”Always have a rollback plan:
# Know the last good commitgit log --oneline -5
# Test rollback process before you need it# (on a test environment if available)Use feature flags for big changes:
// In config.phpdefine('FEATURE_NEW_UI', false);
// In codeif (FEATURE_NEW_UI) { // New code} else { // Old code}Troubleshooting Deployments
Section titled “Troubleshooting Deployments”Deployment Hangs
Section titled “Deployment Hangs”# Cancel with Ctrl+C# SSH into server manuallyssh mymarketingpro
# Check what's happeningcd /var/www/sftp/appsudo git status
# If stuck, kill git processps aux | grep gitsudo kill <pid>
# Try deployment againmake deployMerge Conflicts During Deployment
Section titled “Merge Conflicts During Deployment”# SSH into serverssh mymarketingprocd /var/www/sftp/app
# Check statussudo git status
# If conflicts, decide:# Option 1: Keep production changessudo git checkout --theirs .sudo git add .
# Option 2: Keep main branch changessudo git checkout --ours .sudo git add .
# Complete mergesudo git commit -m "Resolve merge conflict during deployment"
# Try deployment again from localmake deployPermission Errors
Section titled “Permission Errors”# On serverssh mymarketingprocd /var/www/sftp/app
# Check permissionsls -lh
# Fix if neededsudo chown -R www-data:www-data .
# Ensure Git directory is accessiblesudo chmod -R 755 .git/Git Lock File
Section titled “Git Lock File”# On serverssh mymarketingprocd /var/www/sftp/app
# Remove lock filesudo rm -f .git/index.lock
# Try deployment againmake deployAutomated Deployments (Future)
Section titled “Automated Deployments (Future)”Consider setting up CI/CD:
GitHub Actions
Section titled “GitHub Actions”name: Deploy to Productionon: push: branches: [main]jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Deploy run: | ssh ${{ secrets.SSH_HOST }} "cd /var/www/sftp/app && sudo git pull"Benefits of CI/CD
Section titled “Benefits of CI/CD”- Automated testing before deployment
- Consistent deployment process
- Deployment history and audit trail
- Rollback automation
Deployment Checklist Template
Section titled “Deployment Checklist Template”## Deployment: [Feature Name]Date: [YYYY-MM-DD]Deployed by: [Your Name]
### Pre-Deployment- [ ] Code reviewed- [ ] Tested locally- [ ] Database migrations prepared- [ ] Coworker notified- [ ] Backup plan ready
### Deployment- [ ] Deployed with `make deploy`- [ ] Migration run (if needed)- [ ] Production tested- [ ] Error logs checked
### Post-Deployment- [ ] Functionality verified- [ ] No errors in logs- [ ] Coworker notified of completion- [ ] Documentation updated
### Rollback PlanLast good commit: [commit-hash]Command: `git reset --hard [commit-hash] && git push --force && make deploy`
### Notes[Any issues, observations, or follow-ups]Next Steps
Section titled “Next Steps”- Git Workflow - Version control process
- Development Workflow - Development best practices
- Makefile Commands - Command reference