CDMS (Cotton Delivery Management System) Django Production Deployment Guide
============================================================================
1. SETTING UP DIGITALOCEAN SERVER
---------------------------------
- Create a DigitalOcean Droplet (Ubuntu 22.04 LTS recommended)
- Choose size (1vCPU, 1GB RAM minimum for testing; 2GB+ for production)
- Add SSH Key or use root password
- Login via SSH:
ssh root@your_droplet_ip
- Update and upgrade packages:
sudo apt update && sudo apt upgrade -y
- Install essential packages:
sudo apt install python3-pip python3-venv nginx git ufw -y
2. PROJECT SETUP
----------------
- Clone your Django project or use SCP to copy it:
git clone <your-repo-url> cd CDMS
- Create a virtual environment and activate:
python3 -m venv cdmsenven
source cdmsenven/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Setup environment variables (e.g. .env)
3. DATABASE SETUP (PostgreSQL)
------------------------------
- Install PostgreSQL:
sudo apt install postgresql postgresql-contrib -y
- Create a database and user:
sudo -u postgres psql
CREATE DATABASE cdms_db;
CREATE USER cdms_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE cdms_db TO cdms_user;
- Update settings.py with DB credentials.
4. DJANGO CONFIG
----------------
- Apply migrations:
python manage.py migrate
- Create superuser:
python manage.py createsuperuser
- Collect static files:
python manage.py collectstatic
5. GUNICORN + NGINX SETUP
-------------------------
- Install Gunicorn:
pip install gunicorn
- Test Gunicorn:
gunicorn --workers 3 cdms.wsgi:application
- Create Gunicorn systemd service file at /etc/systemd/system/cdms.service:
[Unit]
Description=Gunicorn for CDMS
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/youruser/CDMS
ExecStart=/home/youruser/CDMS/cdmsenven/bin/gunicorn --workers 3 --bind unix:/home/youruser/CDMS/
[Install]
WantedBy=multi-user.target
- Start and enable service:
sudo systemctl start cdms
sudo systemctl enable cdms
- Configure Nginx:
sudo nano /etc/nginx/sites-available/cdms
server {
listen 80;
server_name your_domain_or_ip;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/youruser/CDMS;
location / {
include proxy_params;
proxy_pass http://unix:/home/youruser/CDMS/cdms.sock;
- Enable Nginx config:
sudo ln -s /etc/nginx/sites-available/cdms /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
6. ACCESS & REMOTE EDITING
--------------------------
- Use Git to push code from development machine to a GitHub repo
- SSH into server and pull:
git pull origin main
- Or use SCP to copy files:
scp -r /your/local/dir user@your_droplet_ip:/home/youruser/CDMS
- After updates:
source cdmsenven/bin/activate
python manage.py migrate
python manage.py collectstatic --noinput
sudo systemctl restart cdms
7. SECURITY & UFW
-----------------
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
8. OPTIONAL - HTTPS with Let's Encrypt
--------------------------------------
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your_domain.com
Done! You now have a fully deployed Django app in production.