mirror of
https://github.com/thecyberlearn/hostinger-django-demo.git
synced 2026-08-18 07:52:56 +00:00
🎉 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2.9 KiB
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
Option B: Using Git (recommended)
# 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:
-
Service won't start:
sudo journalctl -u django-demo -f -
Static files not loading:
cd /home/ubuntu/django-demo source venv/bin/activate python manage.py collectstatic --noinput sudo systemctl restart django-demo -
Database errors:
- Check PostgreSQL is running:
sudo systemctl status postgresql - Verify database settings in
.env
- Check PostgreSQL is running:
-
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