hostinger-django-demo/DEPLOYMENT_GUIDE.md
thecyberlearn 2f3f1ea867 Initial commit: Django demo project for VPS deployment
🎉 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 21:50:08 +05:30

2.9 KiB

VPS Deployment Guide

Prerequisites

Before starting, make sure you have:

  • Ubuntu 20.04+ VPS with root/sudo access
  • Your VPS IP address
  • SSH key or password for VPS access
  • Domain name (optional, can use IP address)

Step 1: Prepare Local Files

Clean up your local project:

rm -rf venv/
rm -f db.sqlite3
rm -rf staticfiles/
rm -f requirements_full.txt

Step 2: Upload to VPS

Option A: Using SCP (if you have the files locally)

# Replace YOUR_VPS_IP with your actual IP
scp -r . root@YOUR_VPS_IP:/home/ubuntu/django-demo
# On your VPS, clone the repository
ssh root@YOUR_VPS_IP
cd /home/ubuntu
git clone YOUR_REPO_URL django-demo

Step 3: Run Deployment Script

SSH into your VPS and run:

ssh root@YOUR_VPS_IP
cd /home/ubuntu/django-demo
sudo bash deploy/deploy.sh

Step 4: Configure Environment

Edit the .env file:

sudo nano /home/ubuntu/django-demo/.env

Set these values:

SECRET_KEY=your-super-secret-key-here-make-it-long-and-random
DEBUG=False
ALLOWED_HOSTS=your-domain.com,www.your-domain.com,YOUR_VPS_IP
DATABASE_URL=postgresql://demo_user:your_password@localhost:5432/demo_db
SECURE_SSL_REDIRECT=False  # Set to True after SSL setup

Step 5: Update Domain in Nginx

Edit nginx configuration:

sudo nano /etc/nginx/sites-available/django-demo

Replace yourdomain.com with your actual domain or IP.

Step 6: Restart Services

sudo systemctl restart django-demo
sudo systemctl restart nginx

Step 7: Test Deployment

Check if everything is working:

# Check service status
sudo systemctl status django-demo
sudo systemctl status nginx

# View logs if there are issues
sudo journalctl -u django-demo -f

Visit your website: http://YOUR_VPS_IP or http://your-domain.com

Troubleshooting

Common Issues:

  1. Service won't start:

    sudo journalctl -u django-demo -f
    
  2. Static files not loading:

    cd /home/ubuntu/django-demo
    source venv/bin/activate
    python manage.py collectstatic --noinput
    sudo systemctl restart django-demo
    
  3. Database errors:

    • Check PostgreSQL is running: sudo systemctl status postgresql
    • Verify database settings in .env
  4. Permission errors:

    sudo chown -R www-data:www-data /home/ubuntu/django-demo
    

Optional: SSL Certificate (Let's Encrypt)

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com

After SSL setup, update .env:

SECURE_SSL_REDIRECT=True

Management Commands

# Restart Django
sudo systemctl restart django-demo

# View logs
sudo journalctl -u django-demo -f

# Update application
sudo bash /home/ubuntu/django-demo/deploy/update.sh

# Access Django shell
cd /home/ubuntu/django-demo
source venv/bin/activate
python manage.py shell