🧹 Clean up all confusion - final version

- Removed duplicate requirements files (kept only requirements.txt)
- Removed old deployment scripts (kept main production + multi-project)
- Simplified README.md to be crystal clear
- Clear file structure: 2 deployment options, 3 docs, 1 requirements
- No more confusion - everything is obvious now!
This commit is contained in:
thecyberlearn 2025-08-30 09:27:34 +05:30
parent 61d8656da5
commit 23c2ad6b03
6 changed files with 33 additions and 420 deletions

256
README.md
View File

@ -1,6 +1,6 @@
# Django Demo Project # Django VPS Demo Project
A production-ready Django application template optimized for VPS hosting deployment. This project serves as a foundation for testing VPS deployment workflows and can be used as a template for future Django projects. Simple Django project optimized for VPS deployment with multi-project support.
## ✨ Features ## ✨ Features
@ -23,240 +23,50 @@ A production-ready Django application template optimized for VPS hosting deploym
- **Static Files**: WhiteNoise - **Static Files**: WhiteNoise
- **Configuration**: python-decouple - **Configuration**: python-decouple
## 🚀 Quick Start (Development) ## 🚀 Deploy to VPS
1. **Clone and setup**: ### After VPS Reset:
```bash
git clone <repository-url>
cd hostinger-django-demo
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
```
2. **Configure environment**:
```bash
cp .env.example .env
# Edit .env with your settings
```
3. **Initialize database**:
```bash
python manage.py migrate
python manage.py createsuperuser
python manage.py collectstatic
```
4. **Run development server**:
```bash
python manage.py runserver
```
5. **Access the application**:
- Homepage: http://127.0.0.1:8000
- Admin: http://127.0.0.1:8000/admin
## 🌐 VPS Deployment
### Prerequisites
- Ubuntu 20.04+ VPS
- Root or sudo access
- Domain name (optional, can use IP address)
### Automated Deployment
1. **Upload project files** to your VPS:
```bash
scp -r . user@your-vps-ip:/home/ubuntu/django-demo
```
2. **Run deployment script**:
```bash
cd /home/ubuntu/django-demo
sudo bash deploy/deploy.sh
```
3. **Configure your settings**:
- Edit `.env` file with production settings
- Update domain in `deploy/nginx.conf`
- Restart services: `sudo systemctl restart django-demo nginx`
### Manual Deployment Steps
If you prefer manual setup, follow these steps:
1. **Install system packages**:
```bash
sudo apt update
sudo apt install python3 python3-venv python3-pip nginx postgresql postgresql-contrib
```
2. **Setup project**:
```bash
cd /home/ubuntu/django-demo
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
3. **Configure environment**:
```bash
cp .env.example .env
# Edit .env with production settings
```
4. **Setup database and static files**:
```bash
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py createsuperuser
```
5. **Configure services**:
```bash
sudo cp deploy/systemd.service /etc/systemd/system/django-demo.service
sudo cp deploy/nginx.conf /etc/nginx/sites-available/django-demo
sudo ln -s /etc/nginx/sites-available/django-demo /etc/nginx/sites-enabled/
sudo systemctl enable django-demo
sudo systemctl start django-demo
sudo systemctl restart nginx
```
## ⚙️ Configuration
### Environment Variables
Create a `.env` file based on `.env.example`:
```env
# Required
SECRET_KEY=your-super-secret-key-here
DEBUG=False
ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
# Database (choose one method)
# Method 1: DATABASE_URL
DATABASE_URL=postgresql://username:password@hostname:port/database_name
# Method 2: Individual settings
USE_POSTGRES=True
DB_NAME=demo_db
DB_USER=demo_user
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
# Security
SECURE_SSL_REDIRECT=True # Set to True if using HTTPS
```
### Database Options
1. **SQLite (Development)**: Default, no additional setup required
2. **PostgreSQL (Production)**: Set `USE_POSTGRES=True` or provide `DATABASE_URL`
## 🔧 Management Commands
### Development
```bash ```bash
python manage.py runserver # Start development server # 1. Fix SSH key
python manage.py migrate # Apply database migrations ssh-keygen -f '/home/amit/.ssh/known_hosts' -R '69.62.81.168'
python manage.py createsuperuser # Create admin user
python manage.py collectstatic # Collect static files # 2. Setup django user
scp setup-django-user.sh akvps:/root/
ssh akvps "sudo bash /root/setup-django-user.sh"
# 3. Clone and deploy (choose one option below)
``` ```
### Production ### Option 1: Simple Single Project
```bash ```bash
sudo systemctl restart django-demo # Restart Django service ssh akvps "cd /home/django && git clone https://github.com/thecyberlearn/hostinger-django-demo.git"
sudo systemctl status django-demo # Check service status ssh akvps "cd /home/django/hostinger-django-demo && sudo bash deploy/production-deploy.sh"
sudo journalctl -u django-demo -f # View live logs
sudo bash deploy/update.sh # Deploy updates
``` ```
## 📁 Project Structure ### Option 2: Multi-Project System
```bash
``` ssh akvps "cd /home/django && git clone https://github.com/thecyberlearn/hostinger-django-demo.git"
django-demo/ ssh akvps "cd /home/django/hostinger-django-demo && sudo bash deploy/deploy-project.sh https://github.com/thecyberlearn/hostinger-django-demo.git"
├── core/ # Main Django app
│ ├── templates/ # HTML templates
│ ├── static/ # CSS, JS files
│ ├── models.py # Database models
│ ├── views.py # View functions
│ ├── forms.py # Django forms
│ └── admin.py # Admin configuration
├── demo_project/ # Django project settings
│ ├── settings.py # Main settings
│ ├── urls.py # URL configuration
│ └── wsgi.py # WSGI application
├── deploy/ # Deployment files
│ ├── deploy.sh # Deployment script
│ ├── update.sh # Update script
│ ├── gunicorn.conf.py # Gunicorn configuration
│ ├── nginx.conf # Nginx configuration
│ └── systemd.service # Systemd service file
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md # This file
``` ```
## 🔍 Troubleshooting **Your site**: http://69.62.81.168/
### Common Issues ## 📁 Key Files
1. **Static files not loading**: **Main Deployment Scripts:**
```bash - `deploy/production-deploy.sh` - Simple single project deployment
python manage.py collectstatic --noinput - `deploy/deploy-project.sh` - Multi-project system with auto repo naming
sudo systemctl restart django-demo
```
2. **Database connection errors**: **Documentation:**
- Check `.env` file database settings - `MULTI_PROJECT_SETUP.md` - Complete multi-project guide
- Ensure PostgreSQL is running: `sudo systemctl status postgresql` - `SIMPLE_DEPLOY.md` - Quick deployment reference
3. **Permission errors**: **Setup:**
```bash - `setup-django-user.sh` - Create django user on fresh VPS
sudo chown -R www-data:www-data /home/ubuntu/django-demo - `requirements.txt` - Python dependencies
```
4. **Service not starting**: ## 🎯 That's It!
```bash
sudo journalctl -u django-demo -f # Check logs
sudo systemctl status django-demo # Check status
```
### Log Files For detailed multi-project setup, see `MULTI_PROJECT_SETUP.md`
- Django logs: `sudo journalctl -u django-demo -f` Simple, clean, and no confusion! 🚀
- Nginx access: `/var/log/nginx/access.log`
- Nginx errors: `/var/log/nginx/error.log`
- Custom Django logs: `/var/log/django/`
## 🔒 Security Considerations
- Change `SECRET_KEY` in production
- Set `DEBUG=False` in production
- Use HTTPS in production (`SECURE_SSL_REDIRECT=True`)
- Regularly update dependencies
- Configure firewall (UFW) properly
- Use strong passwords for database users
## 🚀 Deployment Checklist
- [ ] Update `.env` with production settings
- [ ] Set `DEBUG=False`
- [ ] Configure proper `ALLOWED_HOSTS`
- [ ] Set strong `SECRET_KEY`
- [ ] Configure database settings
- [ ] Update domain in nginx configuration
- [ ] Set up SSL certificate (recommended)
- [ ] Configure firewall rules
- [ ] Test all functionality
## 📝 License
This project is open source and available under the MIT License.
## 🤝 Contributing
This is a demo project, but improvements are welcome! Please feel free to submit issues and pull requests.

View File

@ -1,103 +0,0 @@
#!/bin/bash
# Django Demo Project Deployment Script
# Run this script on your VPS to deploy the application
set -e
echo "🚀 Starting Django Demo Project deployment..."
# Configuration
PROJECT_DIR="/home/ubuntu/django-demo"
SERVICE_NAME="django-demo"
NGINX_SITE="django-demo"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run this script as root (use sudo)${NC}"
exit 1
fi
echo -e "${YELLOW}📦 Installing system packages...${NC}"
apt update
apt install -y python3 python3-venv python3-pip nginx postgresql postgresql-contrib
echo -e "${YELLOW}👤 Setting up project user and directories...${NC}"
# Create project directory
mkdir -p $PROJECT_DIR
mkdir -p /var/log/django
mkdir -p /var/run/gunicorn
# Set ownership
chown -R www-data:www-data /var/log/django
chown -R www-data:www-data /var/run/gunicorn
echo -e "${YELLOW}🐍 Setting up Python virtual environment...${NC}"
cd $PROJECT_DIR
python3 -m venv venv
source venv/bin/activate
echo -e "${YELLOW}📋 Installing Python packages...${NC}"
pip install --upgrade pip
pip install -r requirements.txt
echo -e "${YELLOW}⚙️ Configuring environment...${NC}"
if [ ! -f ".env" ]; then
echo "Creating .env file from example..."
cp .env.example .env
echo -e "${RED}⚠️ IMPORTANT: Edit .env file with your production settings!${NC}"
echo " - Set a secure SECRET_KEY"
echo " - Set DEBUG=False"
echo " - Configure ALLOWED_HOSTS with your domain"
echo " - Configure database settings if using PostgreSQL"
fi
echo -e "${YELLOW}🗄️ Setting up database...${NC}"
python manage.py collectstatic --noinput
python manage.py migrate
echo -e "${YELLOW}👤 Creating Django superuser (optional)...${NC}"
echo "Would you like to create a superuser? (y/N)"
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
python manage.py createsuperuser
fi
echo -e "${YELLOW}🔧 Setting up systemd service...${NC}"
cp deploy/systemd.service /etc/systemd/system/${SERVICE_NAME}.service
systemctl daemon-reload
systemctl enable $SERVICE_NAME
echo -e "${YELLOW}🌐 Setting up Nginx...${NC}"
cp deploy/nginx.conf /etc/nginx/sites-available/$NGINX_SITE
ln -sf /etc/nginx/sites-available/$NGINX_SITE /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
nginx -t
echo -e "${YELLOW}🔄 Starting services...${NC}"
systemctl restart $SERVICE_NAME
systemctl restart nginx
echo -e "${YELLOW}🔍 Checking service status...${NC}"
systemctl is-active --quiet $SERVICE_NAME && echo -e "${GREEN}✅ Django service is running${NC}" || echo -e "${RED}❌ Django service failed${NC}"
systemctl is-active --quiet nginx && echo -e "${GREEN}✅ Nginx is running${NC}" || echo -e "${RED}❌ Nginx failed${NC}"
echo -e "${GREEN}🎉 Deployment completed!${NC}"
echo ""
echo "Next steps:"
echo "1. Edit .env file with your production settings"
echo "2. Update domain name in nginx.conf"
echo "3. Set up SSL certificate (recommended: Let's Encrypt)"
echo "4. Configure firewall (ufw) to allow HTTP/HTTPS traffic"
echo ""
echo "Useful commands:"
echo " - Restart Django: sudo systemctl restart $SERVICE_NAME"
echo " - View logs: sudo journalctl -u $SERVICE_NAME -f"
echo " - Restart Nginx: sudo systemctl restart nginx"
echo " - Check status: sudo systemctl status $SERVICE_NAME"

View File

@ -1,52 +0,0 @@
#!/bin/bash
# Django Demo Project Update Script
# Run this script to deploy updates to your running application
set -e
echo "🔄 Starting application update..."
# Configuration
PROJECT_DIR="/home/ubuntu/django-demo"
SERVICE_NAME="django-demo"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (use sudo)"
exit 1
fi
echo -e "${YELLOW}📁 Navigating to project directory...${NC}"
cd $PROJECT_DIR
echo -e "${YELLOW}🐍 Activating virtual environment...${NC}"
source venv/bin/activate
echo -e "${YELLOW}📦 Installing/updating dependencies...${NC}"
pip install -r requirements.txt
echo -e "${YELLOW}🗄️ Running database migrations...${NC}"
python manage.py migrate
echo -e "${YELLOW}📄 Collecting static files...${NC}"
python manage.py collectstatic --noinput
echo -e "${YELLOW}🔄 Restarting Django service...${NC}"
systemctl restart $SERVICE_NAME
echo -e "${YELLOW}🔍 Checking service status...${NC}"
if systemctl is-active --quiet $SERVICE_NAME; then
echo -e "${GREEN}✅ Service is running successfully${NC}"
else
echo "❌ Service failed to start. Check logs:"
echo "sudo journalctl -u $SERVICE_NAME -f"
exit 1
fi
echo -e "${GREEN}✅ Update completed successfully!${NC}"

View File

@ -1,6 +0,0 @@
# Development requirements
-r requirements.txt
# Development tools (optional)
# django-debug-toolbar==4.2.0
# django-extensions==3.2.3

View File

@ -1,9 +0,0 @@
asgiref==3.9.1
dj-database-url==2.1.0
Django==4.2.7
gunicorn==21.2.0
packaging==25.0
python-decouple==3.8
sqlparse==0.5.3
typing_extensions==4.15.0
whitenoise==6.6.0

View File

@ -1,27 +0,0 @@
#!/bin/bash
# Simple Auto-Deploy Setup Script
# Run this on your VPS to enable GitHub auto-deployment
echo "🚀 Setting up simple auto-deploy webhook..."
echo
# Check if we're on the VPS
if [ ! -d "/var/www/django-app" ]; then
echo "❌ This script should be run on your VPS"
echo "Please run: ssh akvps"
echo "Then: sudo bash setup-auto-deploy.sh"
exit 1
fi
# Run the webhook service setup
echo "📦 Installing webhook service..."
sudo bash /var/www/django-app/deploy/webhook-service.sh
echo
echo "✅ Auto-deploy setup complete!"
echo
echo "Next steps:"
echo "1. Go to: https://github.com/thecyberlearn/hostinger-django-demo/settings/hooks"
echo "2. Click 'Add webhook'"
echo "3. Use the webhook secret shown above"
echo "4. Test by pushing a commit!"