# YouTube Clone Deployment Checklist

## 🚀 Pre-Deployment Checklist

### ✅ Server Requirements
- [ ] **Linux Server** (Ubuntu 18.04+ or CentOS 7+)
- [ ] **Python 2.7** (as specified in your virtualenv path)
- [ ] **SSH Access** with key-based authentication
- [ ] **Sudo/Root Access** for system configuration
- [ ] **Domain Name** pointing to server IP
- [ ] **PostgreSQL** (recommended) or MySQL/SQLite

### ✅ Files to Upload
Upload these files to `/home/fnkjyinw/youtube/`:

#### Core Application Files
- [ ] **All Django project files** (entire youtube directory)
- [ ] **requirements.txt** with all dependencies
- [ ] **manage.py** Django management script
- [ ] **static/** directory with CSS/JS files
- [ ] **media/** directory (create if not exists)
- [ ] **templates/** directory with HTML templates

#### Deployment Scripts
- [ ] **deploy-simple.sh** (recommended)
- [ ] **deploy.sh** (full version)
- [ ] **youtube.service** (systemd service)
- [ ] **nginx-youtube.conf** (Nginx configuration)

#### Documentation
- [ ] **DEPLOYMENT_GUIDE.md** (detailed instructions)
- [ ] **DEPLOYMENT_CHECKLIST.md** (this file)

## 🔧 Step-by-Step Deployment

### Step 1: Connect to Server
```bash
# SSH into your server
ssh fnkjyinw@your-server-ip

# Navigate to project directory
cd /home/fnkjyinw/youtube
```

### Step 2: Verify Files
```bash
# Check if all files are present
ls -la

# Verify Django project structure
ls -la youtube_project/
ls -la videos/
ls -la accounts/
```

### Step 3: Set Up Virtual Environment
```bash
# Check if virtual environment exists
ls -la /home/fnkjyinw/virtualenv/youtube/2.7/bin/

# Activate virtual environment
source /home/fnkjyinw/virtualenv/youtube/2.7/bin/activate

# Verify Python version
python --version  # Should be Python 2.7.x
```

### Step 4: Install Dependencies
```bash
# Install Django and required packages
pip install django==1.11.* pillow django-crispy-forms crispy-bootstrap5

# Install production packages
pip install gunicorn psycopg2-binary

# Verify installation
pip list | grep django
```

### Step 5: Configure Django Settings
```bash
# Edit settings.py for production
nano youtube_project/settings.py

# Update these settings:
DEBUG = False
ALLOWED_HOSTS = ['your-domain.com', 'www.your-domain.com', '127.0.0.1']
STATIC_ROOT = '/home/fnkjyinw/youtube/static/'
MEDIA_ROOT = '/home/fnkjyinw/youtube/media/'
```

### Step 6: Database Setup
```bash
# If using PostgreSQL
sudo -u postgres createdb youtube_db

# Run migrations
python manage.py migrate

# Create superuser
python manage.py createsuperuser
# Username: admin
# Email: admin@example.com
# Password: admin123
```

### Step 7: Collect Static Files
```bash
# Collect all static files
python manage.py collectstatic --noinput

# Verify static files
ls -la static/
```

### Step 8: Set Permissions
```bash
# Set proper permissions
chmod -R 755 /home/fnkjyinw/youtube
chmod -R 777 /home/fnkjyinw/youtube/static
chmod -R 777 /home/fnkjyinw/youtube/media
```

### Step 9: Test Django Development Server
```bash
# Test with Django's development server first
python manage.py runserver 0.0.0.0:8001

# Test in another terminal
curl http://127.0.0.1:8001
```

### Step 10: Start Production Server
```bash
# Stop any existing processes
pkill -f gunicorn
pkill -f python

# Start Gunicorn
gunicorn --workers 3 --bind 127.0.0.1:8000 youtube_project.wsgi:application --daemon

# Check if running
ps aux | grep gunicorn
netstat -tulpn | grep 8000
```

### Step 11: Configure Nginx (Optional)
```bash
# Install Nginx if not installed
sudo apt update && sudo apt install nginx

# Copy Nginx config
sudo cp nginx-youtube.conf /etc/nginx/sites-available/youtube
sudo ln -s /etc/nginx/sites-available/youtube /etc/nginx/sites-enabled/

# Test Nginx config
sudo nginx -t

# Restart Nginx
sudo systemctl restart nginx
```

### Step 12: Set Up Systemd Service (Optional)
```bash
# Copy service file
sudo cp youtube.service /etc/systemd/system/

# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable youtube.service
sudo systemctl start youtube.service

# Check status
sudo systemctl status youtube.service
```

## 🧪 Testing & Verification

### Basic Tests
```bash
# Test local access
curl http://127.0.0.1:8000

# Test with browser (if domain configured)
curl http://your-domain.com

# Check Django admin
curl http://127.0.0.1:8000/admin/
```

### Functionality Tests
- [ ] **Homepage loads** correctly
- [ ] **Admin panel** accessible (/admin/)
- [ ] **Static files** loading (CSS/JS)
- [ ] **Database connection** working
- [ ] **User registration** works
- [ ] **Video upload** works
- [ ] **Video playback** works

## 🚨 Common Issues & Solutions

### Issue 1: Permission Denied
```bash
# Fix permissions
sudo chown -R fnkjyinw:fnkjyinw /home/fnkjyinw/youtube
chmod -R 755 /home/fnkjyinw/youtube
```

### Issue 2: Virtual Environment Not Found
```bash
# Create new virtual environment
virtualenv /home/fnkjyinw/virtualenv/youtube/2.7
source /home/fnkjyinw/virtualenv/youtube/2.7/bin/activate
pip install -r requirements.txt
```

### Issue 3: Database Connection Error
```bash
# Check database status
sudo systemctl status postgresql

# Create database
sudo -u postgres createdb youtube_db

# Update settings.py with correct database credentials
```

### Issue 4: Static Files 404
```bash
# Collect static files again
python manage.py collectstatic --noinput

# Check permissions
ls -la static/
chmod -R 777 static/
```

### Issue 5: Gunicorn Not Starting
```bash
# Check for errors
gunicorn --workers 3 --bind 127.0.0.1:8000 youtube_project.wsgi:application

# Check logs
tail -f /var/log/gunicorn.log
```

## 📊 Monitoring & Maintenance

### Check Server Status
```bash
# Check processes
ps aux | grep gunicorn
ps aux | grep nginx

# Check ports
netstat -tulpn | grep :8000
netstat -tulpn | grep :80

# Check disk space
df -h

# Check memory
free -m
```

### View Logs
```bash
# Gunicorn logs
tail -f /var/log/gunicorn.log

# Nginx logs
sudo tail -f /var/log/nginx/error.log

# Django logs (if configured)
tail -f /home/fnkjyinw/youtube/django.log
```

## 🎯 Final Verification

### Production Checklist
- [ ] **HTTPS enabled** (SSL certificate)
- [ ] **Firewall configured** (only necessary ports open)
- [ ] **Backup strategy** in place
- [ ] **Monitoring** set up
- [ ] **Performance optimized** (caching enabled)
- [ ] **Security hardened** (DEBUG=False, secure settings)

### Success Indicators
- ✅ **Website loads** at your domain
- ✅ **All pages work** without errors
- ✅ **Video upload** and playback functional
- ✅ **Admin panel** accessible
- ✅ **Static files** loading correctly
- ✅ **Database operations** working

---

## 🆘 Emergency Commands

### Quick Restart
```bash
# Restart everything
pkill -f gunicorn
pkill -f nginx
cd /home/fnkjyinw/youtube
source /home/fnkjyinw/virtualenv/youtube/2.7/bin/activate
gunicorn --workers 3 --bind 127.0.0.1:8000 youtube_project.wsgi:application --daemon
sudo systemctl restart nginx
```

### Emergency Debug
```bash
# Run in development mode for debugging
python manage.py runserver 0.0.0.0:8001
```

---

**Deployment completed successfully when all checklist items are marked!** 🎉
