Step-by-Step Hosting Django Project (Django + Postgres) on Hostinger VPS
STEP 1: Buy and Access Your VPS
Go to https://www.hostinger.com and purchase a Linux VPS plan.
During setup:
Choose Ubuntu 22.04 LTS or similar as your OS.
Set your root password.
Hostinger will email you:
IP address
SSH username (root)
Password
STEP 2: SSH into VPS
From your terminal:
ssh root@your_vps_ip
STEP 3: Install Required Packages
apt update && apt upgrade -y
# Install Python, pip, venv, git, PostgreSQL, nginx
apt install python3 python3-pip python3-venv git nginx postgresql postgresql-
contrib -y
STEP 4: Configure PostgreSQL
Log into PostgreSQL:
sudo -u postgres psql
Create DB, user, and password:
CREATE DATABASE proximity_db;
CREATE USER proximity_user WITH PASSWORD 'strongpassword';
ALTER ROLE proximity_user SET client_encoding TO 'utf8';
ALTER ROLE proximity_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE proximity_user SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE proximity_db TO proximity_user;
\q
Test the credentials using psql or from Django settings.
STEP 5: Clone Your Project and Set Up Virtual Environment
cd /opt/
git clone https://github.com/yourusername/proximity-based-market.git
cd proximity-based-market
# Set up virtualenv
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
Make sure gunicorn is in your requirements.txt.
STEP 6: Django Settings for Production
Edit settings.py:
Set DEBUG = False
Add your server IP/domain to ALLOWED_HOSTS
ALLOWED_HOSTS = ['your_domain.com', 'your_server_ip']
Set correct DB settings in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'proximity_db',
'USER': 'proximity_user',
'PASSWORD': 'strongpassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
STEP 7: Apply Migrations and Collect Static Files
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
STEP 8: Set Up Gunicorn
Tst it first:
gunicorn proximity.wsgi:application --bind 127.0.0.1:8000
If it works, create a systemd service to keep it running:
nano /etc/systemd/system/gunicorn.service
Paste the following:
[Unit]
Description=gunicorn daemon for Proximity Market
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/opt/proximity-based-market
ExecStart=/opt/proximity-based-market/venv/bin/gunicorn --workers 3 --bind
127.0.0.1:8000 proximity.wsgi:application
[Install]
WantedBy=multi-user.target
systemctl daemon-reexec
systemctl start gunicorn
systemctl enable gunicornSTEP 10: Secure with SSL (Optional but Recommended)
STEP 9: Configure Nginx as Reverse Proxy
nano /etc/nginx/sites-available/proximity
Paste:
server {
listen 80;
server_name your_domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /opt/proximity-based-market;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Enable the config:
ln -s /etc/nginx/sites-available/proximity /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
STEP 10: Secure with SSL (Optional but Recommended)
Install Certbot:
apt install certbot python3-certbot-nginx -y
Get HTTPS:
certbot --nginx -d your_domain.com
STEP 11: Done – Visit Your Site
Visit http://your_domain.com or https://your_domain.com and your Django project
should be live!