0% found this document useful (0 votes)
7 views3 pages

deploy using vps

This document provides a step-by-step guide for hosting a Django project with PostgreSQL on a Hostinger VPS. It covers purchasing a VPS, setting up the server environment, configuring PostgreSQL, cloning the project, and setting up Gunicorn and Nginx as a reverse proxy. Additionally, it includes optional steps for securing the site with SSL and concludes with instructions to access the live site.

Uploaded by

Erdey Syoum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

deploy using vps

This document provides a step-by-step guide for hosting a Django project with PostgreSQL on a Hostinger VPS. It covers purchasing a VPS, setting up the server environment, configuring PostgreSQL, cloning the project, and setting up Gunicorn and Nginx as a reverse proxy. Additionally, it includes optional steps for securing the site with SSL and concludes with instructions to access the live site.

Uploaded by

Erdey Syoum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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!

You might also like